|
--- |
|
language: |
|
- en |
|
tags: |
|
- text-generation-inference |
|
--- |
|
|
|
# Model Card for OPT Spell Generation |
|
|
|
### Model Description |
|
|
|
<!-- Provide a longer summary of what this model is. --> |
|
|
|
This model is a fine-tuned **opt-125m** model for the generation of *D&D 5th edition spells* |
|
|
|
- **Language(s) (NLP):** English |
|
- **Finetuned from model:** [opt-125m](https://huggingface.co/facebook/opt-125m) |
|
- **Dataset used for fine-tuning:** [m-elio/spell_generation](https://huggingface.co/datasets/m-elio/spell_generation) |
|
|
|
## Prompt Format |
|
|
|
This prompt format based on the Alpaca model was used for fine-tuning: |
|
|
|
```python |
|
"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n" \ |
|
f"### Instruction:\n{instruction}\n\n### Response:\n{response}" |
|
``` |
|
|
|
It is recommended to use the same prompt in inference to obtain the best results! |
|
|
|
## Output Format |
|
|
|
The output format for a generated spell should be the following: |
|
|
|
``` |
|
Name: |
|
Level: |
|
School: |
|
Classes: |
|
Casting time: |
|
Range: |
|
Duration: |
|
Components: [If no components are required, then this field has a None value] |
|
Material cost: [If there is no "M" character in the Components field, then this field is skipped] |
|
Description: |
|
``` |
|
|
|
Example: |
|
|
|
``` |
|
Name: The Shadow |
|
Level: 1 |
|
School: Evocation |
|
Classes: Bard, Cleric, Druid, Ranger, Sorcerer, Warlock, Wizard |
|
Casting time: 1 Action |
|
Range: Self |
|
Duration: Concentration, Up To 1 Minute |
|
Components: V, S, M |
|
Material cost: a small piece of cloth |
|
Description: You touch a creature within range. The target must make a Dexterity saving throw. On a failed save, the target takes 2d6 psychic damage and is charmed by you. On a successful save, the target takes half as much damage. |
|
At Higher Levels. When you cast this spell using a spell slot of 4th level or higher, the damage increases by 1d6 for each slot level above 1st. |
|
``` |
|
|
|
## Example use |
|
|
|
|
|
```python |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
|
model_id = "m-elio/spell_generation_opt-125m" |
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_id) |
|
model = AutoModelForCausalLM.from_pretrained(model_id) |
|
|
|
instruction = "Write a spell for the 5th edition of the Dungeons & Dragons game." |
|
|
|
prompt = "Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n" \ |
|
f"### Instruction:\n{instruction}\n\n### Response:\n" |
|
|
|
tokenized_input = tokenizer(prompt, return_tensors="pt") |
|
outputs = model.generate(**tokenized_input, max_length=512) |
|
|
|
print(tokenizer.batch_decode(outputs.detach().cpu().numpy()[:, tokenized_input.input_ids.shape[1]:], skip_special_tokens=True)[0]) |
|
``` |
|
|