Update README.md
Browse files
README.md
CHANGED
@@ -10,24 +10,31 @@ This is a repository for fine-tuned CodeLlama-7b model in the Hugging Face Trans
|
|
10 |
# Model use
|
11 |
|
12 |
```python
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
```
|
32 |
|
33 |
# Training setup
|
|
|
10 |
# Model use
|
11 |
|
12 |
```python
|
13 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
14 |
+
|
15 |
+
# Load pre-trained model and tokenizer
|
16 |
+
model_name = 'JetBrains/CodeLlama-7B-Kexer'
|
17 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
18 |
+
model = AutoModelForCausalLM.from_pretrained(model_name).to('cuda')
|
19 |
+
|
20 |
+
# Create and encode input
|
21 |
+
input_text = """\
|
22 |
+
This function takes an integer n and returns factorial of a number:
|
23 |
+
fun factorial(n: Int): Int {\
|
24 |
+
"""
|
25 |
+
input_ids = tokenizer.encode(
|
26 |
+
input_text, return_tensors='pt'
|
27 |
+
).to('cuda')
|
28 |
+
|
29 |
+
# Generate
|
30 |
+
output = model.generate(
|
31 |
+
input_ids, max_length=150, num_return_sequences=1,
|
32 |
+
no_repeat_ngram_size=2, early_stopping=True
|
33 |
+
)
|
34 |
+
|
35 |
+
# Decode output
|
36 |
+
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
37 |
+
print(generated_text)
|
38 |
```
|
39 |
|
40 |
# Training setup
|