meelfy / pytorch_pretrained_bert Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
When I call from_pretrained, the code runs into this error:
File "/home/gregory.werner/.local/lib/python3.6/site-packages/pytorch_pretrained_bert/tokenization.py", line 197, in from_pretrained
tokenizer = cls(resolved_vocab_file, *inputs, **kwargs)
TypeError: init() got an unexpected keyword argument 'max_len'
Hi,
I use pytorch_pretrained_BERT/examples/python run_lm_finetuning.py
to fit the model with monolingual set of sentences. I use bert multilingual cased model.
Once the model is fine-tuned, I get the loss for given sentences with the following code:
def get_score(sentence, model):
tokenize_input = tokenizer.tokenize(sentence)
tensor_input = torch.tensor([tokenizer.convert_tokens_to_ids(tokenize_input)])
model.eval()
predictions=model(tensor_input)
loss_fct = torch.nn.CrossEntropyLoss()
loss = loss_fct(predictions.squeeze(),tensor_input.squeeze()).data
return math.exp(loss)
sentence = "ﺶﻋﺮﺴﺗﺎﻧ؛ ﺩ پښﺕﻭ ﺶﻋﺭپﻮﻬﻧې ﻥﻭی پړﺍﻭ - ﺕﺎﻧﺩ"
tokenizer = BertTokenizer.from_pretrained('bert-base-multilingual-cased')
stats=torch.load('pytorch_model.bin')
bertMaskedLM = BertForMaskedLM.from_pretrained('bert-base-multilingual-cased', state_dict=stats)
print(get_score(sentence, bertMaskedLM))
78637.05198167797
bertMaskedLM_orig = BertForMaskedLM.from_pretrained('bert-base-multilingual-cased')
print(get_score(sentence, bertMaskedLM_orig))
7.919475431571431
The strange thing is that the fine-tuned model returns much higher loss scores, even if the evaluated sentence appeared in monolingual training data.
Is something I am doing wrong? I just want to check how well the given sentence fits into LM.
Regards and thanks in advance
hi ,nice work
When i use this package, BertModel.from_pretrained('bert-base-uncased'), it's always download when program restart, Can I just download it once?
for line 169, I faced RunTimeError 'pow not implemented for Half' training a model. For all pow functions are used under torch as torch.pow() except this one. Is there a probability to miss this one ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.