Instructions to use mrm8488/bert2bert_shared-turkish-summarization with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mrm8488/bert2bert_shared-turkish-summarization with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "summarization" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # pip install "transformers<5.0.0" from transformers import pipeline pipe = pipeline("summarization", model="mrm8488/bert2bert_shared-turkish-summarization")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("mrm8488/bert2bert_shared-turkish-summarization") model = AutoModelForSeq2SeqLM.from_pretrained("mrm8488/bert2bert_shared-turkish-summarization", device_map="auto") - Notebooks
- Google Colab
- Kaggle
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 |
|