Text Generation
Transformers
Safetensors
Ancient Greek (to 1453)
llama
papyrology
textual criticism
philology
Ancient Greek
mergekit
Merge
conversational
text-generation-inference
Instructions to use Ericu950/Papy_2_Llama-3.1-8B-Instruct_text with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Ericu950/Papy_2_Llama-3.1-8B-Instruct_text with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Ericu950/Papy_2_Llama-3.1-8B-Instruct_text") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Ericu950/Papy_2_Llama-3.1-8B-Instruct_text") model = AutoModelForCausalLM.from_pretrained("Ericu950/Papy_2_Llama-3.1-8B-Instruct_text", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Ericu950/Papy_2_Llama-3.1-8B-Instruct_text with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Ericu950/Papy_2_Llama-3.1-8B-Instruct_text" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Ericu950/Papy_2_Llama-3.1-8B-Instruct_text", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Ericu950/Papy_2_Llama-3.1-8B-Instruct_text
- SGLang
How to use Ericu950/Papy_2_Llama-3.1-8B-Instruct_text with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Ericu950/Papy_2_Llama-3.1-8B-Instruct_text" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Ericu950/Papy_2_Llama-3.1-8B-Instruct_text", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Ericu950/Papy_2_Llama-3.1-8B-Instruct_text" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Ericu950/Papy_2_Llama-3.1-8B-Instruct_text", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Ericu950/Papy_2_Llama-3.1-8B-Instruct_text with Docker Model Runner:
docker model run hf.co/Ericu950/Papy_2_Llama-3.1-8B-Instruct_text
|
Download README.md from Ericu950/Papy_2_Llama-3.1-8B-Instruct_text: direct link, hf CLI and curl.
- Browser
- Download file 11.5 kB
-
https://huggingface.co/Ericu950/Papy_2_Llama-3.1-8B-Instruct_text/resolve/main/README.md
- Command line
-
hf download hf://Ericu950/Papy_2_Llama-3.1-8B-Instruct_text/README.md
-
curl -L -o README.md https://huggingface.co/Ericu950/Papy_2_Llama-3.1-8B-Instruct_text/resolve/main/README.md
11.5 kB
| license: apache-2.0 | |
| language: | |
| - grc | |
| datasets: | |
| - Ericu950/Papyri_1 | |
| base_model: | |
| - meta-llama/Meta-Llama-3.1-8B-Instruct | |
| library_name: transformers | |
| tags: | |
| - papyrology | |
| - textual criticism | |
| - philology | |
| - Ancient Greek | |
| - mergekit | |
| - merge | |
| # Papy_2_Llama-3.1-8B-Instruct_text | |
| This is a finetuned version Llama-3.1-8B-Instruct specialized on reconstructing spans of 1–20 missing characters in ancient Greek documentary papyri. In spans of 1–10 missing characters it did so with a Character Error Rate of 14.9%, a top-1 accuracy of 73.5%, and top-20 of 85.9% on a test set of 7,811 papyrus editions. It replaces Papy_1_Llama-3.1-8B-Instruct_text. | |
| See https://arxiv.org/abs/2409.13870. | |
| ## Usage | |
| To run the model on a GPU with large memory capacity, follow these steps: | |
| ### 1. Download and load the model | |
| ```python | |
| import json | |
| from transformers import pipeline, AutoTokenizer, LlamaForCausalLM | |
| from accelerate import init_empty_weights, load_checkpoint_and_dispatch | |
| import torch | |
| import warnings | |
| warnings.filterwarnings("ignore", message=".*copying from a non-meta parameter in the checkpoint*") | |
| model_id = "Ericu950/Papy_2_Llama-3.1-8B-Instruct_text" | |
| with init_empty_weights(): | |
| model = LlamaForCausalLM.from_pretrained(model_id) | |
| model = load_checkpoint_and_dispatch( | |
| model, | |
| model_id, | |
| device_map="auto", | |
| offload_folder="offload", | |
| offload_state_dict=True, | |
| ) | |
| tokenizer = AutoTokenizer.from_pretrained(model_id) | |
| generation_pipeline = pipeline( | |
| "text-generation", | |
| model=model, | |
| tokenizer=tokenizer, | |
| device_map="auto", | |
| ) | |
| ``` | |
| ### 2. Run inference on a papyrus fragment of your choice | |
| ```python | |
| papyrus_edition = """ | |
| ετουσ τεταρτου αυτοκρατοροσ καισαροσ ουεσπασιανου σεβαστου ------------------ | |
| ομολογει παυσιριων απολλωνιου του παuσιριωνοσ μητροσ ---------------τωι γεγονοτι αυτωι | |
| εκ τησ γενομενησ και μετηλλαχυιασ αυτου γυναικοσ ------------------------- | |
| απο τησ αυτησ πολεωσ εν αγυιαι συγχωρειν ειναι ---------------------------------- | |
| --------------------σ αυτωι εξ ησ συνεστιν ------------------------------------ | |
| ----τησ αυτησ γενεασ την υπαρχουσαν αυτωι οικιαν ------------ | |
| ------------------ ---------καὶ αιθριον και αυλη απερ ο υιοσ διοκοροσ -------------------------- | |
| --------εγραψεν του δ αυτου διοσκορου ειναι ------------------------------------ | |
| ---------- και προ κατενγεγυηται τα δικαια -------------------------------------- | |
| νησ κατα τουσ τησ χωρασ νομουσ· εαν δε μη --------------------------------------- | |
| υπ αυτου τηι του διοσκορου σημαινομενηι -----------------------------------ενοικισμωι του | |
| ημισουσ μερουσ τησ προκειμενησ οικιασ --------------------------------- διοσκοροσ την τουτων αποχην | |
| ---------------------------------------------μηδ υπεναντιον τουτοισ επιτελειν μηδε | |
| ------------------------------------------------ ανασκευηι κατ αυτησ τιθεσθαι ομολογιαν μηδε | |
| ----------------------------------- επιτελεσαι η χωρισ του κυρια ειναι τα διομολογημενα | |
| παραβαινειν, εκτεινειν δε τον παραβησομενον τωι υιωι διοσκορωι η τοισ παρ αυτου καθ εκαστην | |
| εφοδον το τε βλαβοσ και επιτιμον αργυριου δραχμασ 0 και εισ το δημο[7 missing letters] ισασ και μηθεν | |
| ησσον· δ -----ιων ομολογιαν συνεχωρησεν· | |
| """ | |
| system_prompt = "Fill in the missing letters in this papyrus fragment!" | |
| 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=10, | |
| num_beams=30, # Set this as high as your memory will allow! | |
| num_return_sequences=10, | |
| 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 = "σιον τασ" | |
| print(f"The masked sequence: {real_response}") | |
| for i, content in enumerate(beam_contents, start=1): | |
| print(f"Suggestion {i}: {content}") | |
| ``` | |
| ### Expected Output: | |
| ``` | |
| The masked sequence: σιον τασ | |
| Suggestion 1: σιον τασ | |
| Suggestion 2: σιν τασ ι | |
| Suggestion 3: σ τασ ισα | |
| Suggestion 4: σιου τασ | |
| Suggestion 5: συ τασ ισ | |
| Suggestion 6: ιον τασ ι | |
| Suggestion 7: ν τασ ισα | |
| Suggestion 8: σ ισασ κα | |
| Suggestion 9: σασ τασ ι | |
| Suggestion 10: σιωι τασ | |
| ``` | |
| ## Usage on free tier in Google Colab | |
| 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 will deteriorate significantly!** Follow these steps: | |
| ### Step 1: Connect to free GPU | |
| 1. Click Connect arrow_drop_down near the top right of the notebook. | |
| 2. Select Change runtime type. | |
| 3. In the modal window, select T4 GPU as your hardware accelerator. | |
| 4. Click Save. | |
| 5. Click the Connect button to connect to your runtime. After some time, the button will present a green checkmark, along with RAM and disk usage graphs. This indicates that a server has successfully been created with your required hardware. | |
| ### Step 2: Install Dependencies | |
| ```python | |
| !pip install -U bitsandbytes | |
| import os | |
| os._exit(00) | |
| ``` | |
| ### Step 3: Download and quantize the model | |
| ```python | |
| from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, pipeline | |
| import torch | |
| quant_config = BitsAndBytesConfig( | |
| load_in_4bit=True, | |
| bnb_4bit_compute_dtype=torch.bfloat16 | |
| ) | |
| model = AutoModelForCausalLM.from_pretrained("Ericu950/Papy_2_Llama-3.1-8B-Instruct_text", | |
| device_map = "auto", quantization_config = quant_config) | |
| tokenizer = AutoTokenizer.from_pretrained("Ericu950/Papy_2_Llama-3.1-8B-Instruct_text") | |
| generation_pipeline = pipeline( | |
| "text-generation", | |
| model=model, | |
| tokenizer=tokenizer, | |
| device_map="auto", | |
| ) | |
| ``` | |
| ### Step 4: Run inference on a papyrus fragment of your choice | |
| ```python | |
| papyrus_edition = """ | |
| ετουσ τεταρτου αυτοκρατοροσ καισαροσ ουεσπασιανου σεβαστου ------------------ | |
| ομολογει παυσιριων απολλωνιου του παuσιριωνοσ μητροσ ---------------τωι γεγονοτι αυτωι | |
| εκ τησ γενομενησ και μετηλλαχυιασ αυτου γυναικοσ ------------------------- | |
| απο τησ αυτησ πολεωσ εν αγυιαι συγχωρειν ειναι ---------------------------------- | |
| --------------------σ αυτωι εξ ησ συνεστιν ------------------------------------ | |
| ----τησ αυτησ γενεασ την υπαρχουσαν αυτωι οικιαν ------------ | |
| ------------------ ---------καὶ αιθριον και αυλη απερ ο υιοσ διοκοροσ -------------------------- | |
| --------εγραψεν του δ αυτου διοσκορου ειναι ------------------------------------ | |
| ---------- και προ κατενγεγυηται τα δικαια -------------------------------------- | |
| νησ κατα τουσ τησ χωρασ νομουσ· εαν δε μη --------------------------------------- | |
| υπ αυτου τηι του διοσκορου σημαινομενηι -----------------------------------ενοικισμωι του | |
| ημισουσ μερουσ τησ προκειμενησ οικιασ --------------------------------- διοσκοροσ την τουτων αποχην | |
| ---------------------------------------------μηδ υπεναντιον τουτοισ επιτελειν μηδε | |
| ------------------------------------------------ ανασκευηι κατ αυτησ τιθεσθαι ομολογιαν μηδε | |
| ----------------------------------- επιτελεσαι η χωρισ του κυρια ειναι τα διομολογημενα | |
| παραβαινειν, εκτεινειν δε τον παραβησομενον τωι υιωι διοσκορωι η τοισ παρ αυτου καθ εκαστην | |
| εφοδον το τε βλαβοσ και επιτιμον αργυριου δραχμασ 0 και εισ το δημο[7 missing letters] ισασ και μηθεν | |
| ησσον· δ -----ιων ομολογιαν συνεχωρησεν· | |
| """ | |
| system_prompt = "Fill in the missing letters in this papyrus fragment!" | |
| 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=10, | |
| num_beams=30, # Set this as high as your memory will allow! | |
| num_return_sequences=10, | |
| 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 = "σιον τασ" | |
| print(f"The masked characters: {real_response}") | |
| for i, content in enumerate(beam_contents, start=1): | |
| print(f"Suggestion {i}: {content}") | |
| ``` | |
| ### Expected Output: | |
| ``` | |
| The masked characters: σιον τασ | |
| Suggestion 1: σιον τα 00· | |
| Suggestion 2: σιον αυτωι· | |
| Suggestion 3: σιον 00 00 | |
| Suggestion 4: σιον και 0· | |
| Suggestion 5: σιον τα 00·· | |
| Suggestion 6: σιον τασ 0 | |
| Suggestion 7: σιον τα 000· | |
| Suggestion 8: σιον τα 0ο | |
| Suggestion 9: σιον τασασ· | |
| Suggestion 10: σιον τα 00 | |
| ``` | |
| Observe that performance declines! If we change | |
| ```python | |
| load_in_4bit=True, | |
| bnb_4bit_compute_dtype=torch.bfloat16 | |
| ``` | |
| in the second cell to | |
| ```python | |
| load_in_8bit=True, | |
| ``` | |
| we get | |
| ``` | |
| The masked characters: σιον τασ | |
| Suggestion 1: σιον τασ | |
| Suggestion 2: σιν τασ ι | |
| Suggestion 3: σ τασ ισα | |
| Suggestion 4: σιου τασ | |
| Suggestion 5: σ ισασ κα | |
| Suggestion 6: συ τασ ισ | |
| Suggestion 7: σασ τασ ι | |
| Suggestion 8: ν τασ ισα | |
| Suggestion 9: ιον τασ ι | |
| Suggestion 10: σισ τασ ι | |
| ``` | |
| ## Information about configuration for merging | |
| The finetuned model was remerged with Llama-3.1-8B-Instruct using the [TIES](https://arxiv.org/abs/2306.01708) merge method. This did not afect CER or top-1 accuracy, but the effect on top-20 accuracy was positive. The following YAML configuration was used: | |
| ```yaml | |
| models: | |
| - model: original # Llama 3.1 | |
| - model: DDbDP_reconstructer_5 # A model fintuned on the 95 % of the DDbDP for 11 epochs | |
| parameters: | |
| density: 1.1 | |
| weight: 0.5 | |
| merge_method: ties | |
| base_model: original # Llama 3.1 | |
| parameters: | |
| normalize: true | |
| dtype: bfloat16 | |
| ``` | |