swagat-panda
commited on
Commit
•
bd41d53
1
Parent(s):
c283acc
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
To use this model you have import this class
|
33 |
+
|
34 |
+
```commandline
|
35 |
+
from transformers import BertPreTrainedModel, BertModel
|
36 |
+
from transformers.modeling_outputs import TokenClassifierOutput
|
37 |
+
from torch import nn
|
38 |
+
from torch.nn import CrossEntropyLoss
|
39 |
+
import torch
|
40 |
+
|
41 |
+
from torchcrf import CRF
|
42 |
+
from transformers import BertTokenizerFast
|
43 |
+
from transformers import BertTokenizerFast, Trainer, TrainingArguments
|
44 |
+
from transformers.trainer_utils import IntervalStrategy
|
45 |
+
|
46 |
+
class BertCRF(BertPreTrainedModel):
|
47 |
+
|
48 |
+
_keys_to_ignore_on_load_unexpected = [r"pooler"]
|
49 |
+
|
50 |
+
def __init__(self, config):
|
51 |
+
super().__init__(config)
|
52 |
+
self.num_labels = config.num_labels
|
53 |
+
|
54 |
+
self.bert = BertModel(config, add_pooling_layer=False)
|
55 |
+
self.dropout = nn.Dropout(config.hidden_dropout_prob)
|
56 |
+
self.classifier = nn.Linear(config.hidden_size, config.num_labels)
|
57 |
+
self.crf = CRF(num_tags=config.num_labels, batch_first=True)
|
58 |
+
self.init_weights()
|
59 |
+
|
60 |
+
def forward(
|
61 |
+
self,
|
62 |
+
input_ids=None,
|
63 |
+
attention_mask=None,
|
64 |
+
token_type_ids=None,
|
65 |
+
position_ids=None,
|
66 |
+
head_mask=None,
|
67 |
+
inputs_embeds=None,
|
68 |
+
labels=None,
|
69 |
+
output_attentions=None,
|
70 |
+
output_hidden_states=None,
|
71 |
+
return_dict=None,
|
72 |
+
):
|
73 |
+
r"""
|
74 |
+
labels (:obj:`torch.LongTensor` of shape :obj:`(batch_size, sequence_length)`, `optional`):
|
75 |
+
Labels for computing the token classification loss. Indices should be in ``[0, ..., config.num_labels -
|
76 |
+
1]``.
|
77 |
+
"""
|
78 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
79 |
+
|
80 |
+
outputs = self.bert(
|
81 |
+
input_ids,
|
82 |
+
attention_mask=attention_mask,
|
83 |
+
token_type_ids=token_type_ids,
|
84 |
+
position_ids=position_ids,
|
85 |
+
head_mask=head_mask,
|
86 |
+
inputs_embeds=inputs_embeds,
|
87 |
+
output_attentions=output_attentions,
|
88 |
+
output_hidden_states=output_hidden_states,
|
89 |
+
return_dict=return_dict,
|
90 |
+
)
|
91 |
+
|
92 |
+
sequence_output = outputs[0]
|
93 |
+
sequence_output = self.dropout(sequence_output)
|
94 |
+
logits = self.classifier(sequence_output)
|
95 |
+
|
96 |
+
loss = None
|
97 |
+
if labels is not None:
|
98 |
+
log_likelihood, tags = self.crf(logits, labels), self.crf.decode(logits)
|
99 |
+
loss = 0 - log_likelihood
|
100 |
+
else:
|
101 |
+
tags = self.crf.decode(logits)
|
102 |
+
tags = torch.Tensor(tags)
|
103 |
+
|
104 |
+
if not return_dict:
|
105 |
+
output = (tags,) + outputs[2:]
|
106 |
+
return ((loss,) + output) if loss is not None else output
|
107 |
+
|
108 |
+
return loss, tags
|
109 |
+
```
|
110 |
+
Some sample output from the model
|
111 |
+
|
112 |
+
This model uses a different kind of labelling system from it will not only be able to detect language, as well as it can detect the POS of the respective language
|
113 |
+
|
114 |
+
| Types | Output |
|
115 |
+
|--------------------|-------------------------------------------------------------------------------------------------------------------|
|
116 |
+
| English | [{'words': ['my', 'name', 'is', 'swagat'], 'labels': ['en-DET', 'enNN', 'en-VB', 'en-NN']}] |
|
117 |
+
| Hindi | [{'words': ['मेरा', 'नाम', 'स्वागत', 'है'], 'labels': ['hi-PRP', 'hi-NN', 'hi-NNP', 'hi-VM']}] |
|
118 |
+
| Hindi Romanised | [{'words': ['mera', 'naam', 'swagat', 'hai'], 'labels': ['hi_romPRP', 'hi_rom-NN', 'hi_rom-NNP', 'hi_rom-VM']}] |
|
119 |
+
| Gujarati | [{'words': ['મારું', 'નામ', 'સ્વગત', 'છે'], 'labels': ['gu-PRP', 'guNN', 'gu-NNP', 'gu-VAUX']}] |
|
120 |
+
| Gujarati Romanised | [{'words': ['maru', 'naam', 'swagat', 'che'], 'labels': ['gu_romPRP', 'gu_rom-NN', 'gu_rom-NNP', 'gu_rom-VAUX']}] |
|
121 |
+
|
122 |
+
|
123 |
+
- **Developed by:** Swagat Panda
|
124 |
+
- **Finetuned from model :** google/muril-base-cased
|
125 |
+
|
126 |
+
### Model Sources
|
127 |
+
- **Paper :** https://www.academia.edu/87916386/MULTILINGUAL_APPROACH_TOWARDS_THE_NATIVE_AND_ROMANISED_SCRIPTS_FOR_INDIAN_LANGUGE_CONTEXT_ON_POS_TAGGING?source=swp_share
|
128 |
+
|