swagat-panda commited on
Commit
7182399
1 Parent(s): 8a9466e

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +129 -0
README.md ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ - gu
6
+ - mr
7
+ - hi
8
+ ---
9
+ # Model Card for Model ID
10
+
11
+
12
+ ## Model Details
13
+ The technique of marking the words in a phrase to their appropriate POS
14
+ tags is known as part-of-speech tagging (POS tagging or POST). There are
15
+ two sorts of POS tagging algorithms: rule-based and stochastic, and
16
+ monolingual and multilingual are different types from a modelling
17
+ standpoint. POS tags provide grammatical context to a sentence, which can
18
+ be employed in NLP tasks such as NER, NLU and QNA systems.
19
+ In this research field, a lot of researchers had already tried to propose
20
+ various novel approaches, tags and models like Weightless Artificial
21
+ Neural Network (WANN), different forms of CRF, Bi-LSTM CRF, and
22
+ transformers, various techniques for language tag mixed POS tags to
23
+ handle mixed languages. All this research work leads to the enhancement
24
+ or creating a benchmark for different popular and low resource languages,
25
+ In the state of monolingual or multilingual context. In this model
26
+ we are trying to achieve state-of-the-art model for the Indian language
27
+ context in both native and its Romanised format.
28
+
29
+ ### Model Description
30
+
31
+ The model has been trained on the romanized forms of the Indian languages as well as English, Hindi, Gujarati, and Marathi.i.e(en,gu,mr,hi,gu_romanised,mr_romanised,hi_romanised)
32
+
33
+ To use this model you have import this class
34
+
35
+ ```commandline
36
+ rom transformers import BertPreTrainedModel, BertModel
37
+ from transformers.modeling_outputs import TokenClassifierOutput
38
+ from torch import nn
39
+ from torch.nn import CrossEntropyLoss
40
+ import torch
41
+
42
+ from torchcrf import CRF
43
+ from transformers import BertTokenizerFast
44
+ from transformers import BertTokenizerFast, Trainer, TrainingArguments
45
+ from transformers.trainer_utils import IntervalStrategy
46
+
47
+ class BertCRF(BertPreTrainedModel):
48
+
49
+ _keys_to_ignore_on_load_unexpected = [r"pooler"]
50
+
51
+ def __init__(self, config):
52
+ super().__init__(config)
53
+ self.num_labels = config.num_labels
54
+
55
+ self.bert = BertModel(config, add_pooling_layer=False)
56
+ self.dropout = nn.Dropout(config.hidden_dropout_prob)
57
+ self.classifier = nn.Linear(config.hidden_size, config.num_labels)
58
+ self.crf = CRF(num_tags=config.num_labels, batch_first=True)
59
+ self.init_weights()
60
+
61
+ def forward(
62
+ self,
63
+ input_ids=None,
64
+ attention_mask=None,
65
+ token_type_ids=None,
66
+ position_ids=None,
67
+ head_mask=None,
68
+ inputs_embeds=None,
69
+ labels=None,
70
+ output_attentions=None,
71
+ output_hidden_states=None,
72
+ return_dict=None,
73
+ ):
74
+ r"""
75
+ labels (:obj:`torch.LongTensor` of shape :obj:`(batch_size, sequence_length)`, `optional`):
76
+ Labels for computing the token classification loss. Indices should be in ``[0, ..., config.num_labels -
77
+ 1]``.
78
+ """
79
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
80
+
81
+ outputs = self.bert(
82
+ input_ids,
83
+ attention_mask=attention_mask,
84
+ token_type_ids=token_type_ids,
85
+ position_ids=position_ids,
86
+ head_mask=head_mask,
87
+ inputs_embeds=inputs_embeds,
88
+ output_attentions=output_attentions,
89
+ output_hidden_states=output_hidden_states,
90
+ return_dict=return_dict,
91
+ )
92
+
93
+ sequence_output = outputs[0]
94
+ sequence_output = self.dropout(sequence_output)
95
+ logits = self.classifier(sequence_output)
96
+
97
+ loss = None
98
+ if labels is not None:
99
+ log_likelihood, tags = self.crf(logits, labels), self.crf.decode(logits)
100
+ loss = 0 - log_likelihood
101
+ else:
102
+ tags = self.crf.decode(logits)
103
+ tags = torch.Tensor(tags)
104
+
105
+ if not return_dict:
106
+ output = (tags,) + outputs[2:]
107
+ return ((loss,) + output) if loss is not None else output
108
+
109
+ return loss, tags
110
+ ```
111
+ Some sample output from the model
112
+
113
+ | Types | Output |
114
+ |--------------------|----------------------------------------------------------------------------------------|
115
+ | English | [{'words': ['my', 'name', 'is', 'swagat'], 'labels': ['DET', 'NN', 'VB', 'NN']}] |
116
+ | Hindi | [{'words': ['मेरा', 'नाम', 'स्वागत', 'है'], 'labels': ['PRP', 'NN', 'NNP', 'VM']}] |
117
+ | Hindi Romanised | [{'words': ['mera', 'naam', 'swagat', 'hai'], 'labels': [‘PRP', 'NN', 'NNP', 'VM']}] |
118
+ | Gujarati | [{'words': ['મારું', 'નામ', 'સ્વગત', 'છે'], 'labels': ['PRP', 'NN', 'NNP', 'VAUX']}] |
119
+ | Gujarati Romanised | [{'words': ['maru', 'naam', 'swagat', 'che'], 'labels': ['PRP', 'NN', 'NNP', 'VAUX']}] |
120
+
121
+
122
+
123
+
124
+ - **Developed by:** Swagat Panda
125
+ - **Finetuned from model :** google/muril-base-cased
126
+
127
+ ### Model Sources [optional]
128
+ - **Paper :** https://www.academia.edu/87916386/MULTILINGUAL_APPROACH_TOWARDS_THE_NATIVE_AND_ROMANISED_SCRIPTS_FOR_INDIAN_LANGUGE_CONTEXT_ON_POS_TAGGING?source=swp_share
129
+