Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
language:
|
4 |
+
- it
|
5 |
+
---
|
6 |
+
|
7 |
+
This model is a fine-tuned version of [bart-it](https://huggingface.co/morenolq/bart-it) on a lfqa dataset.
|
8 |
+
|
9 |
+
### Usage
|
10 |
+
|
11 |
+
```python
|
12 |
+
import torch
|
13 |
+
from transformers import AutoTokenizer, AutoModel, AutoModelForSeq2SeqLM
|
14 |
+
|
15 |
+
model_name = "efederici/bart-lfqa-it"
|
16 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
17 |
+
|
18 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
19 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
20 |
+
model = model.to(device)
|
21 |
+
|
22 |
+
query = "<string>"
|
23 |
+
|
24 |
+
documents = [
|
25 |
+
"<string>",
|
26 |
+
"<string>",
|
27 |
+
...
|
28 |
+
]
|
29 |
+
|
30 |
+
docs = "<p> " + " <p> ".join([d for d in documents])
|
31 |
+
q = "Q: {}\n\nC: {}".format(query, docs)
|
32 |
+
|
33 |
+
input = tokenizer(query_and_docs, truncation=True, padding=True, return_tensors="pt")
|
34 |
+
|
35 |
+
generated_answers_encoded = model.generate(
|
36 |
+
input_ids=input["input_ids"].to(device),
|
37 |
+
attention_mask=input["attention_mask"].to(device),
|
38 |
+
min_length=64,
|
39 |
+
max_length=256,
|
40 |
+
do_sample=False,
|
41 |
+
early_stopping=True,
|
42 |
+
num_beams=8,
|
43 |
+
temperature=1.0,
|
44 |
+
top_k=None,
|
45 |
+
top_p=None,
|
46 |
+
eos_token_id=tokenizer.eos_token_id,
|
47 |
+
no_repeat_ngram_size=3,
|
48 |
+
num_return_sequences=1
|
49 |
+
)
|
50 |
+
|
51 |
+
output = tokenizer.batch_decode(generated_answers_encoded, skip_special_tokens=True,clean_up_tokenization_spaces=True)[0]
|
52 |
+
print(output)
|
53 |
+
```
|
54 |
+
|
55 |
+
### Author
|
56 |
+
- Edoardo Federici: [Twitter](https://twitter.com/edofederici) | [LinkedIn](https://www.linkedin.com/in/edoardo-federici-01341b1b6)
|