Instructions to use rajaatif786/TickerExtraction with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use rajaatif786/TickerExtraction with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="rajaatif786/TickerExtraction", device_map="auto")# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("rajaatif786/TickerExtraction") model = AutoModel.from_pretrained("rajaatif786/TickerExtraction", device_map="auto") - Notebooks
- Google Colab
- Kaggle
| class EntityBertNet(nn.Module): | |
| def __init__(self): | |
| super(EntityBertNet, self).__init__() | |
| config = BertConfig.from_pretrained(TRAINED_WEIGHTS) | |
| self.bert_base = BertModel.from_pretrained(TRAINED_WEIGHTS, config=config) | |
| self.fc = nn.Linear(HIDDEN_OUTPUT_FEATURES, NUM_CLASSES) | |
| def forward(self, input_ids, attn_mask, entity_indices): | |
| # BERT | |
| bert_output, _ = self.bert_base(input_ids=input_ids, attention_mask=attn_mask,return_dict=False) | |
| # max pooling at entity locations | |
| entity_pooled_output = EntityBertNet.pooled_output(bert_output, entity_indices) | |
| # fc layer (softmax activation done in loss function) | |
| x = self.fc(entity_pooled_output) | |
| return x | |
| @staticmethod | |
| def pooled_output(bert_output, indices): | |
| #print(bert_output) | |
| outputs = torch.gather(input=bert_output, dim=1, index=indices) | |
| pooled_output, _ = torch.max(outputs, dim=1) | |
| return pooled_output |