Edit model card

BERTweet.BR: A Pre-Trained Language Model for Tweets in Portuguese

Having the same architecture of BERTweet we trained our model from scratch following RoBERTa pre-training procedure on a corpus of approximately 9GB containing 100M Portuguese Tweets.

Usage

Normalized Inputs

import torch
from transformers import AutoModel, AutoTokenizer 

model = AutoModel.from_pretrained('melll-uff/bertweetbr')
tokenizer = AutoTokenizer.from_pretrained('melll-uff/bertweetbr', normalization=False)

# INPUT TWEETS ALREADY NORMALIZED!
inputs = [
    "Procuro um amor , que seja bom pra mim ... vou procurar , eu vou até o fim :nota_musical:",
    "Que jogo ontem @USER :mãos_juntas:",
    "Demojizer para Python é :polegar_para_cima: e está disponível em HTTPURL"]

encoded_inputs = tokenizer(inputs, return_tensors="pt", padding=True)

with torch.no_grad():
    last_hidden_states = model(**encoded_inputs)

# CLS Token of last hidden states. Shape: (number of input sentences, hidden sizeof the model)
last_hidden_states[0][:,0,:]

tensor([[-0.1430, -0.1325,  0.1595,  ..., -0.0802, -0.0153, -0.1358],
        [-0.0108,  0.1415,  0.0695,  ...,  0.1420,  0.1153, -0.0176],
        [-0.1854,  0.1866,  0.3163,  ..., -0.2117,  0.2123, -0.1907]])

Normalize raw input Tweets

from emoji import demojize
import torch
from transformers import AutoModel, AutoTokenizer 

model = AutoModel.from_pretrained('melll-uff/bertweetbr')
tokenizer = AutoTokenizer.from_pretrained('melll-uff/bertweetbr', normalization=True)

inputs = [
   "Procuro um amor , que seja bom pra mim ... vou procurar , eu vou até o fim 🎵",
   "Que jogo ontem @cristiano 🙏",
   "Demojizer para Python é 👍 e está disponível em https://pypi.org/project/emoji/"]

tokenizer.demojizer = lambda x: demojize(x, language='pt')

[tokenizer.normalizeTweet(s) for s in inputs]

# Tokenizer first normalizes tweet sentences
['Procuro um amor , que seja bom pra mim ... vou procurar , eu vou até o fim :nota_musical:',
'Que jogo ontem @USER :mãos_juntas:',
'Demojizer para Python é :polegar_para_cima: e está disponível em HTTPURL']

encoded_inputs = tokenizer(inputs, return_tensors="pt", padding=True)

with torch.no_grad():
   last_hidden_states = model(**encoded_inputs)

# CLS Token of last hidden states. Shape: (number of input sentences, hidden sizeof the model)
last_hidden_states[0][:,0,:]

tensor([[-0.1430, -0.1325,  0.1595,  ..., -0.0802, -0.0153, -0.1358],
       [-0.0108,  0.1415,  0.0695,  ...,  0.1420,  0.1153, -0.0176],
       [-0.1854,  0.1866,  0.3163,  ..., -0.2117,  0.2123, -0.1907]])

Mask Filling with Pipeline

from transformers import pipeline

model_name = 'melll-uff/bertweetbr'
tokenizer = AutoTokenizer.from_pretrained('melll-uff/bertweetbr', normalization=False)

filler_mask = pipeline("fill-mask", model=model_name, tokenizer=tokenizer)
filler_mask("Rio é a <mask> cidade do Brasil.", top_k=5)

# Output
[{'sequence': 'Rio é a melhor cidade do Brasil.',
 'score': 0.9871652126312256,
 'token': 120,
 'token_str': 'm e l h o r'},
{'sequence': 'Rio é a pior cidade do Brasil.',
 'score': 0.005050931591540575,
 'token': 316,
 'token_str': 'p i o r'},
{'sequence': 'Rio é a maior cidade do Brasil.',
 'score': 0.004420778248459101,
 'token': 389,
 'token_str': 'm a i o r'},
{'sequence': 'Rio é a minha cidade do Brasil.',
 'score': 0.0021856199018657207,
 'token': 38,
 'token_str': 'm i n h a'},
{'sequence': 'Rio é a segunda cidade do Brasil.',
 'score': 0.0002110043278662488,
 'token': 667,
 'token_str': 's e g u n d a'}]
Downloads last month
392
Inference Examples
This model does not have enough activity to be deployed to Inference API (serverless) yet. Increase its social visibility and check back later, or deploy to Inference Endpoints (dedicated) instead.