krsnaman commited on
Commit
08a758f
1 Parent(s): 54aeb66

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +36 -24
README.md CHANGED
@@ -24,8 +24,17 @@ licenses:
24
 
25
  # MultiIndicWikiBioSS
26
 
27
- This repository contains the [IndicBARTSS](https://huggingface.co/ai4bharat/IndicBARTSS) checkpoint finetuned on the 9 languages of [IndicWikiBio](https://huggingface.co/datasets/ai4bharat/IndicWikiBio) dataset. For finetuning details,
28
- see the [paper](https://arxiv.org/abs/2203.05437).
 
 
 
 
 
 
 
 
 
29
 
30
 
31
  ## Using this model in `transformers`
@@ -33,38 +42,41 @@ see the [paper](https://arxiv.org/abs/2203.05437).
33
  ```
34
  from transformers import MBartForConditionalGeneration, AutoModelForSeq2SeqLM
35
  from transformers import AlbertTokenizer, AutoTokenizer
36
- tokenizer = AutoTokenizer.from_pretrained("ai4bharat/MultiIndicParaphraseGenerationSS", do_lower_case=False, use_fast=False, keep_accents=True)
37
- # Or use tokenizer = AlbertTokenizer.from_pretrained("ai4bharat/MultiIndicParaphraseGenerationSS", do_lower_case=False, use_fast=False, keep_accents=True)
38
- model = AutoModelForSeq2SeqLM.from_pretrained("ai4bharat/MultiIndicParaphraseGenerationSS")
39
- # Or use model = MBartForConditionalGeneration.from_pretrained("ai4bharat/MultiIndicParaphraseGenerationSS")
 
 
 
40
  # Some initial mapping
41
  bos_id = tokenizer._convert_token_to_id_with_added_voc("<s>")
42
  eos_id = tokenizer._convert_token_to_id_with_added_voc("</s>")
43
  pad_id = tokenizer._convert_token_to_id_with_added_voc("<pad>")
44
- # To get lang_id use any of ['<2as>', '<2bn>', '<2en>', '<2gu>', '<2hi>', '<2kn>', '<2ml>', '<2mr>', '<2or>', '<2pa>', '<2ta>', '<2te>']
 
45
  # 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>".
46
- inp = tokenizer("I am a boy </s> <2en>", add_special_tokens=False, return_tensors="pt", padding=True).input_ids # tensor([[ 466, 1981, 80, 25573, 64001, 64004]])
 
 
 
 
 
 
 
 
 
 
47
 
48
  # For generation. Pardon the messiness. Note the decoder_start_token_id.
49
  model.eval() # Set dropouts to zero
50
- model_output=model.generate(inp, use_cache=True,no_repeat_ngram_size=3,encoder_no_repeat_ngram_size=3, num_beams=4, max_length=20, min_length=1, early_stopping=True, pad_token_id=pad_id, bos_token_id=bos_id, eos_token_id=eos_id, decoder_start_token_id=tokenizer._convert_token_to_id_with_added_voc("<2en>"))
 
 
51
  # Decode to get output strings
52
  decoded_output=tokenizer.decode(model_output[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
53
- print(decoded_output) # I am a boy
54
- # Note that if your output language is not Hindi or Marathi, you should convert its script from Devanagari to the desired language using the Indic NLP Library.
55
- # What if we mask?
56
- inp = tokenizer("I am [MASK] </s> <2en>", add_special_tokens=False, return_tensors="pt", padding=True).input_ids
57
- model_output=model.generate(inp, use_cache=True,no_repeat_ngram_size=3,encoder_no_repeat_ngram_size=3, num_beams=4, max_length=20, min_length=1, early_stopping=True, pad_token_id=pad_id, bos_token_id=bos_id, eos_token_id=eos_id, decoder_start_token_id=tokenizer._convert_token_to_id_with_added_voc("<2en>"))
58
- decoded_output=tokenizer.decode(model_output[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
59
- print(decoded_output) # I am happy
60
- inp = tokenizer("मैं [MASK] हूँ </s> <2hi>", add_special_tokens=False, return_tensors="pt", padding=True).input_ids
61
- model_output=model.generate(inp, use_cache=True, num_beams=4,no_repeat_ngram_size=3,encoder_no_repeat_ngram_size=3, max_length=20, min_length=1, early_stopping=True, pad_token_id=pad_id, bos_token_id=bos_id, eos_token_id=eos_id, decoder_start_token_id=tokenizer._convert_token_to_id_with_added_voc("<2en>"))
62
- decoded_output=tokenizer.decode(model_output[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
63
- print(decoded_output) # मैं जानता हूँ
64
- inp = tokenizer("मला [MASK] पाहिजे </s> <2mr>", add_special_tokens=False, return_tensors="pt", padding=True).input_ids
65
- model_output=model.generate(inp, use_cache=True,no_repeat_ngram_size=3,encoder_no_repeat_ngram_size=3,num_beams=4, max_length=20, min_length=1, early_stopping=True, pad_token_id=pad_id, bos_token_id=bos_id, eos_token_id=eos_id, decoder_start_token_id=tokenizer._convert_token_to_id_with_added_voc("<2en>"))
66
- decoded_output=tokenizer.decode(model_output[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
67
- print(decoded_output) # मला ओळखलं पाहिजे
68
  ```
69
 
70
  ## Benchmarks
 
24
 
25
  # MultiIndicWikiBioSS
26
 
27
+ MultiIndicWikiBioSS is a multilingual, sequence-to-sequence pre-trained model, a [IndicBARTSS](https://huggingface.co/ai4bharat/IndicBARTSS) checkpoint fine-tuned on the 9 languages of [IndicWikiBio](https://huggingface.co/datasets/ai4bharat/IndicWikiBio) dataset. For fine-tuning details,
28
+ see the [paper](https://arxiv.org/abs/2203.05437). You can use MultiIndicWikiBioSS to build biography generation applications for Indian languages by fine-tuning the model with supervised training data. Some salient features of the MultiIndicWikiBioSS are:
29
+
30
+ <ul>
31
+ <li >Supported languages: Assamese, Bengali, Hindi, Oriya, Punjabi, Kannada, Malayalam, Tamil, and Telugu. Not all of these languages are supported by mBART50 and mT5. </li>
32
+ <li >The model is much smaller than the mBART and mT5(-base) models, so less computationally expensive for finetuning and decoding. </li>
33
+ <li> Fine-tuned on an Indic language corpora (34,653 examples). </li>
34
+ <li> Unlike ai4bharat/MultiIndicWikiBioUnified, each language is written in its own script, so you do not need to perform any script mapping to/from Devanagari. </li>
35
+ </ul>
36
+
37
+ You can read more about MultiIndicWikiBioSS in this <a href="https://arxiv.org/abs/2203.05437">paper</a>.
38
 
39
 
40
  ## Using this model in `transformers`
 
42
  ```
43
  from transformers import MBartForConditionalGeneration, AutoModelForSeq2SeqLM
44
  from transformers import AlbertTokenizer, AutoTokenizer
45
+
46
+ tokenizer = AutoTokenizer.from_pretrained("ai4bharat/MultiIndicWikiBioSS", do_lower_case=False, use_fast=False, keep_accents=True)
47
+ # Or use tokenizer = AlbertTokenizer.from_pretrained("ai4bharat/MultiIndicWikiBioSS", do_lower_case=False, use_fast=False, keep_accents=True)
48
+
49
+ model = AutoModelForSeq2SeqLM.from_pretrained("ai4bharat/MultiIndicWikiBioSS")
50
+ # Or use model = MBartForConditionalGeneration.from_pretrained("ai4bharat/MultiIndicWikiBioSS")
51
+
52
  # Some initial mapping
53
  bos_id = tokenizer._convert_token_to_id_with_added_voc("<s>")
54
  eos_id = tokenizer._convert_token_to_id_with_added_voc("</s>")
55
  pad_id = tokenizer._convert_token_to_id_with_added_voc("<pad>")
56
+ # To get lang_id use any of ['<2as>', '<2bn>', '<2hi>', '<2kn>', '<2ml>', '<2or>', '<2pa>', '<2ta>', '<2te>']
57
+
58
  # 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>".
59
+ inp = tokenizer("<TAG> name </TAG> भीखा लाल <TAG> office </TAG> विधायक - 318 - हसनगंज विधान सभा निर्वाचन क्षेत्र , उत्तर प्रदेश <TAG> term </TAG> 1957 से 1962 <TAG> nationality </TAG> भारतीय</s><2hi>", add_special_tokens=False, return_tensors="pt", padding=True).input_ids
60
+
61
+ out = tokenizer("<2hi> भीखा लाल ,भारत के उत्तर प्रदेश की दूसरी विधानसभा सभा में विधायक रहे। </s>", add_special_tokens=False, return_tensors="pt", padding=True).input_ids
62
+
63
+ model_outputs=model(input_ids=inp, decoder_input_ids=out[:,0:-1], labels=out[:,1:])
64
+
65
+ # For loss
66
+ model_outputs.loss ## This is not label smoothed.
67
+
68
+ # For logits
69
+ model_outputs.logits
70
 
71
  # For generation. Pardon the messiness. Note the decoder_start_token_id.
72
  model.eval() # Set dropouts to zero
73
+
74
+ model_output=model.generate(inp, use_cache=True,no_repeat_ngram_size=3,encoder_no_repeat_ngram_size=3, num_beams=4, max_length=20, min_length=1, early_stopping=True, pad_token_id=pad_id, bos_token_id=bos_id, eos_token_id=eos_id, decoder_start_token_id=tokenizer._convert_token_to_id_with_added_voc("<2hi>"))
75
+
76
  # Decode to get output strings
77
  decoded_output=tokenizer.decode(model_output[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
78
+ print(decoded_output) # __भीखा लाल ,भारत के उत्तर प्रदेश की दूसरी विधानसभा सभा में विधायक रहे।
79
+
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  ```
81
 
82
  ## Benchmarks