|
--- |
|
license: apache-2.0 |
|
datasets: |
|
- Ericu950/Papyri_1 |
|
base_model: |
|
- meta-llama/Meta-Llama-3.1-8B-Instruct |
|
library_name: transformers |
|
tags: |
|
- papyrology |
|
- epigraphy |
|
- philology |
|
--- |
|
|
|
# Papy_1_Llama-3.1-8B-Instruct_date |
|
|
|
This is a fine-tuned version of the Llama-3.1-8B-Instruct model, specialized in assigning a date to Greek documentary papyri. On a test set of 1,856 unseen papyri, its predictions were, on average, 21.7 years away from the actual date spans. |
|
|
|
## Usage |
|
|
|
To run the model, use the following code: |
|
|
|
```python |
|
import json |
|
from transformers import pipeline, AutoTokenizer, LlamaForCausalLM |
|
import torch |
|
|
|
papyrus_edition = """ |
|
ετουσ τεταρτου αυτοκρατοροσ καισαροσ ουεσπασιανου σεβαστου ------------------ |
|
ομολογει παυσιριων απολλωνιου του παuσιριωνοσ μητροσ ---------------τωι γεγονοτι αυτωι |
|
εκ τησ γενομενησ και μετηλλαχυιασ αυτου γυναικοσ ------------------------- |
|
απο τησ αυτησ πολεωσ εν αγυιαι συγχωρειν ειναι ---------------------------------- |
|
--------------------σ αυτωι εξ ησ συνεστιν ------------------------------------ |
|
----τησ αυτησ γενεασ την υπαρχουσαν αυτωι οικιαν ------------ |
|
------------------ ---------καὶ αιθριον και αυλη απερ ο υιοσ διοκοροσ -------------------------- |
|
--------εγραψεν του δ αυτου διοσκορου ειναι ------------------------------------ |
|
---------- και προ κατενγεγυηται τα δικαια -------------------------------------- |
|
νησ κατα τουσ τησ χωρασ νομουσ· εαν δε μη --------------------------------------- |
|
υπ αυτου τηι του διοσκορου σημαινομενηι -----------------------------------ενοικισμωι του |
|
ημισουσ μερουσ τησ προκειμενησ οικιασ --------------------------------- διοσκοροσ την τουτων αποχην |
|
---------------------------------------------μηδ υπεναντιον τουτοισ επιτελειν μηδε |
|
------------------------------------------------ ανασκευηι κατ αυτησ τιθεσθαι ομολογιαν μηδε |
|
----------------------------------- επιτελεσαι η χωρισ του κυρια ειναι τα διομολογημενα |
|
παραβαινειν, εκτεινειν δε τον παραβησομενον τωι υιωι διοσκορωι η τοισ παρ αυτου καθ εκαστην |
|
εφοδον το τε βλαβοσ και επιτιμον αργυριου δραχμασ 0 και εισ το δημοσιον τασ ισασ και μηθεν |
|
ησσον· δ -----ιων ομολογιαν συνεχωρησεν· |
|
""" |
|
|
|
model_id = "Ericu950/Papy_1_Llama-3.1-8B-Instruct_date" |
|
|
|
model = LlamaForCausalLM.from_pretrained( |
|
model_id, |
|
device_map="auto", |
|
) |
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_id) |
|
|
|
generation_pipeline = pipeline( |
|
"text-generation", |
|
model=model, |
|
tokenizer=tokenizer, |
|
device_map="auto", |
|
) |
|
|
|
system_prompt = "Date this papyrus fragment to an exact year!" |
|
|
|
input_messages = [ |
|
{"role": "system", "content": system_prompt}, |
|
{"role": "user", "content": papyrus_edition}, |
|
] |
|
|
|
terminators = [ |
|
tokenizer.eos_token_id, |
|
tokenizer.convert_tokens_to_ids("<|eot_id|>") |
|
] |
|
|
|
outputs = generation_pipeline( |
|
input_messages, |
|
max_new_tokens=4, |
|
num_beams=20, |
|
num_return_sequences=1, |
|
early_stopping=True, |
|
) |
|
|
|
beam_contents = [] |
|
for output in outputs: |
|
generated_text = output.get('generated_text', []) |
|
for item in generated_text: |
|
if item.get('role') == 'assistant': |
|
beam_contents.append(item.get('content')) |
|
|
|
real_response = "71 or 72 AD" |
|
|
|
print(f"Year: {real_response}") |
|
for i, content in enumerate(beam_contents, start=1): |
|
print(f"Suggestion {i}: {content}") |
|
``` |
|
|
|
You should get this output: |
|
``` |
|
Year: 71 or 72 AD |
|
Suggestion 1: 71 |
|
``` |
|
|
|
|