Update README.md
Browse files
README.md
CHANGED
@@ -27,9 +27,25 @@ widget:
|
|
27 |
| Test | Rouge2 - mid - recall | 28.65|
|
28 |
| Test | Rouge2 - mid - fmeasure | 29.48|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
|
|
27 |
| Test | Rouge2 - mid - recall | 28.65|
|
28 |
| Test | Rouge2 - mid - fmeasure | 29.48|
|
29 |
|
30 |
+
## Usage
|
31 |
+
|
32 |
+
```python
|
33 |
+
import torch
|
34 |
+
from transformers import BertTokenizerFast, EncoderDecoderModel
|
35 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
36 |
+
ckpt = 'mrm8488/bert2bert_shared-turkish-summarization'
|
37 |
+
tokenizer = BertTokenizerFast.from_pretrained(ckpt)
|
38 |
+
model = EncoderDecoderModel.from_pretrained(ckpt).to(device)
|
39 |
+
|
40 |
+
def generate_summary(text):
|
41 |
+
|
42 |
+
inputs = tokenizer([text], padding="max_length", truncation=True, max_length=512, return_tensors="pt")
|
43 |
+
input_ids = inputs.input_ids.to(device)
|
44 |
+
attention_mask = inputs.attention_mask.to(device)
|
45 |
+
output = model.generate(input_ids, attention_mask=attention_mask)
|
46 |
+
return tokenizer.decode(output[0], skip_special_tokens=True)
|
47 |
+
|
48 |
+
|
49 |
+
text = "Your text here..."
|
50 |
+
generate_summary(text)
|
51 |
|