File size: 2,616 Bytes
467158f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
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-2.7b** model for the generation of *D&D 5th edition spells*

- **Language(s) (NLP):** English
- **Finetuned from model:** [opt-2.7b](https://huggingface.co/facebook/opt-2.7b)
- **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-2.7b"

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])
```