Update README.md
Browse files
README.md
CHANGED
|
@@ -10,8 +10,9 @@ tokenizer = AlbertTokenizer.from_pretrained("prajdabre/IndicBARTTokenizer", do_l
|
|
| 10 |
model = MBartForConditionalGeneration.from_pretrained("prajdabre/IndicBART")
|
| 11 |
|
| 12 |
# First tokenize the input and outputs. The format below is how IndicBART was trained so the input should be "Sentence </s> <2xx>" where xx is the language code. Similarly, the output should be "<2yy> Sentence </s>".
|
| 13 |
-
inp = tokenizer("I am a boy
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
model_outputs=model(input_ids=inp, decoder_input_ids=out[:,0:-1], labels=out[:,1:])
|
| 17 |
|
|
@@ -23,7 +24,7 @@ model_outputs.logits
|
|
| 23 |
|
| 24 |
# For generation. Pardon the messiness. Note the decoder_start_token_id.
|
| 25 |
|
| 26 |
-
model_output=model.generate(inp, use_cache=True, num_beams=4, max_length=20, min_length=1, early_stopping=True, pad_token_id=tokenizer.pad_token_id,
|
| 27 |
|
| 28 |
|
| 29 |
# Decode to get output strings
|
|
@@ -34,7 +35,7 @@ print(decoded_output) # I am a boy
|
|
| 34 |
# What if we mask?
|
| 35 |
|
| 36 |
inp = tokenizer("I am [MASK] </s> <2en>", add_special_tokens=False, return_tensors="pt", padding=True).input_ids
|
| 37 |
-
model_output=model.generate(inp, use_cache=True, num_beams=4, max_length=20, min_length=1, early_stopping=True, pad_token_id=tokenizer.pad_token_id,
|
| 38 |
decoded_output=tokenizer.decode(model_output[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
|
| 39 |
print(decoded_output) # I am happy
|
| 40 |
|
|
|
|
| 10 |
model = MBartForConditionalGeneration.from_pretrained("prajdabre/IndicBART")
|
| 11 |
|
| 12 |
# First tokenize the input and outputs. The format below is how IndicBART was trained so the input should be "Sentence </s> <2xx>" where xx is the language code. Similarly, the output should be "<2yy> Sentence </s>".
|
| 13 |
+
inp = tokenizer("I am a boy <\/s> <2en>", add_special_tokens=False, return_tensors="pt", padding=True).input_ids
|
| 14 |
+
|
| 15 |
+
out = tokenizer("<2hi> मैं एक लड़का हूँ <\/s>", add_special_tokens=False, return_tensors="pt", padding=True).input_ids
|
| 16 |
|
| 17 |
model_outputs=model(input_ids=inp, decoder_input_ids=out[:,0:-1], labels=out[:,1:])
|
| 18 |
|
|
|
|
| 24 |
|
| 25 |
# For generation. Pardon the messiness. Note the decoder_start_token_id.
|
| 26 |
|
| 27 |
+
model_output=model.generate(inp, use_cache=True, num_beams=4, max_length=20, min_length=1, early_stopping=True, pad_token_id=tokenizer.pad_token_id, decoder_start_token_id=tokenizer(["<2en>"], add_special_tokens=False).input_ids[0][0])
|
| 28 |
|
| 29 |
|
| 30 |
# Decode to get output strings
|
|
|
|
| 35 |
# What if we mask?
|
| 36 |
|
| 37 |
inp = tokenizer("I am [MASK] </s> <2en>", add_special_tokens=False, return_tensors="pt", padding=True).input_ids
|
| 38 |
+
model_output=model.generate(inp, use_cache=True, num_beams=4, max_length=20, min_length=1, early_stopping=True, pad_token_id=tokenizer.pad_token_id, decoder_start_token_id=tokenizer(["<2en>"], add_special_tokens=False).input_ids[0][0])
|
| 39 |
decoded_output=tokenizer.decode(model_output[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
|
| 40 |
print(decoded_output) # I am happy
|
| 41 |
|