Update README.md
Browse files
README.md
CHANGED
@@ -21,13 +21,35 @@ This model is fine-tuned on the Ericu950/Papyri_1 dataset, which consists of Gre
|
|
21 |
|
22 |
## Usage
|
23 |
|
24 |
-
To run the model
|
|
|
|
|
25 |
|
26 |
```python
|
27 |
import json
|
28 |
from transformers import pipeline, AutoTokenizer, LlamaForCausalLM
|
29 |
import torch
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
papyrus_edition = """
|
32 |
ετουσ τεταρτου αυτοκρατοροσ καισαροσ ουεσπασιανου σεβαστου ------------------
|
33 |
ομολογει παυσιριων απολλωνιου του παuσιριωνοσ μητροσ ---------------τωι γεγονοτι αυτωι
|
@@ -49,22 +71,6 @@ papyrus_edition = """
|
|
49 |
ησσον· δ -----ιων ομολογιαν συνεχωρησεν·
|
50 |
"""
|
51 |
|
52 |
-
model_id = "Ericu950/Papy_1_Llama-3.1-8B-Instruct_date"
|
53 |
-
|
54 |
-
model = LlamaForCausalLM.from_pretrained(
|
55 |
-
model_id,
|
56 |
-
device_map="auto",
|
57 |
-
)
|
58 |
-
|
59 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
60 |
-
|
61 |
-
generation_pipeline = pipeline(
|
62 |
-
"text-generation",
|
63 |
-
model=model,
|
64 |
-
tokenizer=tokenizer,
|
65 |
-
device_map="auto",
|
66 |
-
)
|
67 |
-
|
68 |
system_prompt = "Date this papyrus fragment to an exact year!"
|
69 |
|
70 |
input_messages = [
|
@@ -80,7 +86,7 @@ terminators = [
|
|
80 |
outputs = generation_pipeline(
|
81 |
input_messages,
|
82 |
max_new_tokens=4,
|
83 |
-
num_beams=
|
84 |
num_return_sequences=1,
|
85 |
early_stopping=True,
|
86 |
)
|
@@ -98,25 +104,25 @@ print(f"Year: {real_response}")
|
|
98 |
for i, content in enumerate(beam_contents, start=1):
|
99 |
print(f"Suggestion {i}: {content}")
|
100 |
```
|
101 |
-
|
102 |
-
You should get this output:
|
103 |
```
|
104 |
Year: 71 or 72 AD
|
105 |
Suggestion 1: 71
|
106 |
```
|
107 |
## Usage on free tier in Google Colab
|
108 |
|
109 |
-
If you don’t have access to larger
|
110 |
|
111 |
### Step 1: Install Dependencies
|
112 |
```
|
113 |
!pip install -U bitsandbytes
|
|
|
|
|
114 |
```
|
115 |
-
After installing, **restart the runtime**.
|
116 |
|
117 |
-
### Step 2:
|
118 |
|
119 |
-
```
|
120 |
|
121 |
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, pipeline
|
122 |
import torch
|
@@ -138,7 +144,10 @@ generation_pipeline = pipeline(
|
|
138 |
tokenizer=tokenizer,
|
139 |
device_map="auto",
|
140 |
)
|
141 |
-
|
|
|
|
|
|
|
142 |
papyrus_edition = """
|
143 |
ετουσ τεταρτου αυτοκρατοροσ καισαροσ ουεσπασιανου σεβαστου ------------------
|
144 |
ομολογει παυσιριων απολλωνιου του παuσιριωνοσ μητροσ ---------------τωι γεγονοτι αυτωι
|
|
|
21 |
|
22 |
## Usage
|
23 |
|
24 |
+
To run the model on a GPU with larger memory, following these steps:
|
25 |
+
|
26 |
+
### 1. Download and load the model
|
27 |
|
28 |
```python
|
29 |
import json
|
30 |
from transformers import pipeline, AutoTokenizer, LlamaForCausalLM
|
31 |
import torch
|
32 |
|
33 |
+
model_id = "Ericu950/Papy_1_Llama-3.1-8B-Instruct_date"
|
34 |
+
|
35 |
+
model = LlamaForCausalLM.from_pretrained(
|
36 |
+
model_id,
|
37 |
+
device_map="auto",
|
38 |
+
)
|
39 |
+
|
40 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
41 |
+
|
42 |
+
generation_pipeline = pipeline(
|
43 |
+
"text-generation",
|
44 |
+
model=model,
|
45 |
+
tokenizer=tokenizer,
|
46 |
+
device_map="auto",
|
47 |
+
)
|
48 |
+
```
|
49 |
+
|
50 |
+
### 2. Run inference on a papyrus fragment of your choice
|
51 |
+
```python
|
52 |
+
# This is a rough transcription of Pap.Ups. 106
|
53 |
papyrus_edition = """
|
54 |
ετουσ τεταρτου αυτοκρατοροσ καισαροσ ουεσπασιανου σεβαστου ------------------
|
55 |
ομολογει παυσιριων απολλωνιου του παuσιριωνοσ μητροσ ---------------τωι γεγονοτι αυτωι
|
|
|
71 |
ησσον· δ -----ιων ομολογιαν συνεχωρησεν·
|
72 |
"""
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
system_prompt = "Date this papyrus fragment to an exact year!"
|
75 |
|
76 |
input_messages = [
|
|
|
86 |
outputs = generation_pipeline(
|
87 |
input_messages,
|
88 |
max_new_tokens=4,
|
89 |
+
num_beams=45, # Set this as high as your memory will allow!
|
90 |
num_return_sequences=1,
|
91 |
early_stopping=True,
|
92 |
)
|
|
|
104 |
for i, content in enumerate(beam_contents, start=1):
|
105 |
print(f"Suggestion {i}: {content}")
|
106 |
```
|
107 |
+
### Expected Output:
|
|
|
108 |
```
|
109 |
Year: 71 or 72 AD
|
110 |
Suggestion 1: 71
|
111 |
```
|
112 |
## Usage on free tier in Google Colab
|
113 |
|
114 |
+
If you don’t have access to a larger GPU but want to try the model out, you can run it in a quantized format in Google Colab. **The quality of the responses might deteriorate significantly.** Follow these steps:
|
115 |
|
116 |
### Step 1: Install Dependencies
|
117 |
```
|
118 |
!pip install -U bitsandbytes
|
119 |
+
import os
|
120 |
+
os._exit(00)
|
121 |
```
|
|
|
122 |
|
123 |
+
### Step 2: Download and quantize the model
|
124 |
|
125 |
+
```python
|
126 |
|
127 |
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, pipeline
|
128 |
import torch
|
|
|
144 |
tokenizer=tokenizer,
|
145 |
device_map="auto",
|
146 |
)
|
147 |
+
```
|
148 |
+
### Step 3: Run inference on a papyrus fragment of your choice
|
149 |
+
```
|
150 |
+
# This is a rough transcription of Pap.Ups. 106
|
151 |
papyrus_edition = """
|
152 |
ετουσ τεταρτου αυτοκρατοροσ καισαροσ ουεσπασιανου σεβαστου ------------------
|
153 |
ομολογει παυσιριων απολλωνιου του παuσιριωνοσ μητροσ ---------------τωι γεγονοτι αυτωι
|