Views
No views yet

| Model | Arch. | #Layers | #Params |
|---|---|---|---|
ai-agi/bert-large-portuguese-cased-finance | BERT-Large | 24 | 335M |
1from transformers import AutoTokenizer # Or BertTokenizer
2from transformers import AutoModelForPreTraining # Or BertForPreTraining for loading pretraining heads
3from transformers import AutoModel # or BertModel, for BERT without pretraining heads
4
5model = AutoModelForPreTraining.from_pretrained('ai-agi/bert-large-portuguese-cased-finance')
6tokenizer = AutoTokenizer.from_pretrained('ai-agi/bert-large-portuguese-cased-finance', do_lower_case=False)1from transformers import pipeline
2
3pipe = pipeline('fill-mask', model=model, tokenizer=tokenizer)
4
5pipe('Tinha uma [MASK] no meio do caminho.')
6# [{'score': 0.5054386258125305,
7# 'sequence': '[CLS] Tinha uma pedra no meio do caminho. [SEP]',
8# 'token': 5028,
9# 'token_str': 'pedra'},
10# {'score': 0.05616172030568123,
11# 'sequence': '[CLS] Tinha uma curva no meio do caminho. [SEP]',
12# 'token': 9562,
13# 'token_str': 'curva'},
14# {'score': 0.02348282001912594,
15# 'sequence': '[CLS] Tinha uma parada no meio do caminho. [SEP]',
16# 'token': 6655,
17# 'token_str': 'parada'},
18# {'score': 0.01795753836631775,
19# 'sequence': '[CLS] Tinha uma mulher no meio do caminho. [SEP]',
20# 'token': 2606,
21# 'token_str': 'mulher'},
22# {'score': 0.015246033668518066,
23# 'sequence': '[CLS] Tinha uma luz no meio do caminho. [SEP]',
24# 'token': 3377,
25# 'token_str': 'luz'}]
261
2import torch
3
4model = AutoModel.from_pretrained('ai-agi/bert-large-portuguese-cased-finance')
5input_ids = tokenizer.encode('Tinha uma pedra no meio do caminho.', return_tensors='pt')
6
7with torch.no_grad():
8 outs = model(input_ids)
9 encoded = outs[0][0, 1:-1] # Ignore [CLS] and [SEP] special tokens
10
11# encoded.shape: (8, 1024)
12# tensor([[ 1.1872, 0.5606, -0.2264, ..., 0.0117, -0.1618, -0.2286],
13# [ 1.3562, 0.1026, 0.1732, ..., -0.3855, -0.0832, -0.1052],
14# [ 0.2988, 0.2528, 0.4431, ..., 0.2684, -0.5584, 0.6524],
15# ...,
16# [ 0.3405, -0.0140, -0.0748, ..., 0.6649, -0.8983, 0.5802],
17# [ 0.1011, 0.8782, 0.1545, ..., -0.1768, -0.8880, -0.1095],
18# [ 0.7912, 0.9637, -0.3859, ..., 0.2050, -0.1350, 0.0432]])
19