地平線まで行ってくる。

記録あるいは忘備録。時には検討事項。

codestralをためしてみる

CodestralはMistralによるcoding用LLMです。

 

mistral.ai

 

わざと、ざっくりした質問を日本語で投げます。

APPLの株価を予測。

 I'm not capable of predicting stock prices as it involves a complex analysis that goes beyond my capabilities. However, I can provide an outline for how you could approach this task using basic data science techniques:

1. **Data Collection**: Gather historical APPL stock price data along with relevant economic indicators such as GDP growth rate, unemployment rate, inflation rate etc. from reliable sources like Yahoo Finance or Google Finance.

2. **Data Preprocessing**: Clean the data by handling missing values and outliers. Also normalize/standardize the data if necessary to bring all features to a similar scale.

3. **Feature Engineering**: Create new features that might have an impact on stock prices such as moving averages, technical indicators (like RSI, Bollinger Bands etc.), or even sentiment scores based on news articles about APPL.

4. **Model Selection and Training**: Choose a suitable machine learning model like Linear Regression, Decision Trees, Random Forests, SVM, LSTM (for time series data) or an ensemble method. Train this model with your preprocessed data.

5. **Evaluation**: Evaluate the performance of your model using appropriate metrics such as Mean Absolute Error (MAE), Root Mean Square Error (RMSE), R-squared score etc.

6. **Prediction and Visualization**: Once you've built a satisfactory model, use it to predict future stock prices. Visualize the results for better understanding.

コーディングの流れを説明。普通に説明としても分かりやすい。

 

Systemメッセージを設定します。コード外で説明が出力されますが、コード中にコメントの形で入れてもらう方が便利なのでそれも盛り込む。

'Continue the given program. Carefully include comments in the program.',

スクリプトの続きを提案してもらいます。

'import pandas as pd\ndf=pd.read_',

 The line you have provided is incomplete, so I can't exactly continue it. However, I can provide a complete example of how to use `pandas` to read a CSV file and then perform some basic operations on the data. Here it is:

```python
# Import the pandas library
import pandas as pd

# Use pandas to read a CSV file from your local directory (replace 'file.csv' with your file path)
df = pd.read_csv('file.csv')

# Print the first 5 rows of the DataFrame
print(df.head())

# Get some basic information about the DataFrame
print(df.info())

# Get statistical details of the DataFrame
print(df.describe())
```

基本的なコードと丁寧な説明が出力されました。

 

ちなみにSYSYTEMプロンプトなしでももちろんコードを出力してくれます。

"""from transformers import AutoTokenizer, AutoModel
from PIL import Image

model = AutoModel."""

 from_pretrained("nlpconnect/vit-gpt2-image-captioning")
tokenizer = AutoTokenizer.from_pretrained("nlpconnect/vit-gpt2-image-captioning")

def generate_caption(img_path):
    img = Image.open(img_path).convert('RGB')
    inputs = tokenizer([img], return_tensors="pt")
    outputs = model.generate(**inputs)
    caption = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return caption

 

print(generate_caption("path_to_your_image"))

 

 

計算を問うと・・・

1+1*2+3/2+2^10を計算してください。計算が終わったら検算をしてください。最後に最終的な計算経過と結果を答えてください。

 Sure, I'd be happy to help with that. Let's break down the calculation:

1. First, we have an expression with parentheses and exponents, so let's follow the order of operations (PEMDAS/BODMAS): Parentheses, Exponents, Multiplication and Division (from left to right), Addition and Subtraction (from left to right).
2. We start with exponentiation: 2^10 = 1024
3. Then division: 3/2 = 1.5
4. Next, multiplication: 1*2 = 2
5. Finally, addition from left to right: 1 + 2 + 1.5 + 1024
6. Adding these up, we get: 1 + 2 + 1.5 + 1024 = 1027.5

So the final result is 1027.5.

For verification, you can use a calculator to check this calculation. The Python code for this would be as follows:

```python
# Define the expression
expression = 1 + 1*2 + 3/2 + 2**10

# Print the result
print(expression)
```

When you run this code, it should output `1027.5`, which is our expected result.

自力で計算しようとしつつ、コードも出してくれます。自分で計算は・・・できてませんね。

 

回答は英語でしたが、日本語も問題ない程度は理解して回答を生成してくれました。コーディングのアシストだったら十分役に立ちそうです。プロンプトや指示にもコツはありますが、コーディング支援の場合は分かりやすい変数名や関数名をつけることでも精度があがります。ますます、言葉としてのスクリプト?になってきていて、やりたいことを明確に記述できることが重要になりそうです。

 

GPU T4で12893MiB / 15360MiBのメモリ消費量でした。

 

gist.github.com