Update README.md
Browse files
README.md
CHANGED
|
@@ -36,21 +36,21 @@ The only limitation you might face is, to get the best results, you will have to
|
|
| 36 |
Use the code below to get started with the model.
|
| 37 |
|
| 38 |
---
|
| 39 |
-
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
| 40 |
-
import torch
|
| 41 |
-
|
| 42 |
-
model = AutoModelForSeq2SeqLM.from_pretrained("yashrane2904/LED_Finetuned").to("cuda")
|
| 43 |
-
tokenizer = AutoTokenizer.from_pretrained("allenai/led-base-16384") # Since it is a fine-tuned version of led-base-16348, we use the same tokenizer as that model used
|
| 44 |
-
LONG_ARTICLE = "Your long text goes here..."
|
| 45 |
-
|
| 46 |
-
input_ids = tokenizer(LONG_ARTICLE, return_tensors="pt").input_ids.to("cuda")
|
| 47 |
-
global_attention_mask = torch.zeros_like(input_ids)
|
| 48 |
-
global_attention_mask[:, 0] = 1
|
| 49 |
-
|
| 50 |
-
sequences_tensor = model.generate(input_ids, global_attention_mask=global_attention_mask, num_beams=10, num_beam_groups=1,repetition_penalty=6.0,max_length=600,min_length=350,temperature=1.5)
|
| 51 |
-
sequences = sequences_tensor.tolist() # Convert Tensor to list of token IDs
|
| 52 |
-
summary = tokenizer.batch_decode(sequences, skip_special_tokens=True) # Decode token IDs into text
|
| 53 |
-
|
| 54 |
print(summary)
|
| 55 |
---
|
| 56 |
|
|
|
|
| 36 |
Use the code below to get started with the model.
|
| 37 |
|
| 38 |
---
|
| 39 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer <br>
|
| 40 |
+
import torch <br>
|
| 41 |
+
<b><i>#Load the model and tokenizer</i></b><br>
|
| 42 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("yashrane2904/LED_Finetuned").to("cuda")<br>
|
| 43 |
+
tokenizer = AutoTokenizer.from_pretrained("allenai/led-base-16384") # Since it is a fine-tuned version of led-base-16348, we use the same tokenizer as that model used<br>
|
| 44 |
+
LONG_ARTICLE = "Your long text goes here..."<br>
|
| 45 |
+
<b><i>#Tokenize the input article</i></b><br>
|
| 46 |
+
input_ids = tokenizer(LONG_ARTICLE, return_tensors="pt").input_ids.to("cuda")<br>
|
| 47 |
+
global_attention_mask = torch.zeros_like(input_ids)<br>
|
| 48 |
+
global_attention_mask[:, 0] = 1<br>
|
| 49 |
+
<b><i>#Generate summaries</i></b><br>
|
| 50 |
+
sequences_tensor = model.generate(input_ids, global_attention_mask=global_attention_mask, num_beams=10, num_beam_groups=1,repetition_penalty=6.0,max_length=600,min_length=350,temperature=1.5)<br>
|
| 51 |
+
sequences = sequences_tensor.tolist() # Convert Tensor to list of token IDs<br>
|
| 52 |
+
summary = tokenizer.batch_decode(sequences, skip_special_tokens=True) # Decode token IDs into text<br>
|
| 53 |
+
<b><i>#Print the generated summary</i></b><br>
|
| 54 |
print(summary)
|
| 55 |
---
|
| 56 |
|