w4ngatang / sent-bias Goto Github PK
View Code? Open in Web Editor NEWCode and test data for "On Measuring Bias in Sentence Encoders", to appear at NAACL 2019.
License: Other
Code and test data for "On Measuring Bias in Sentence Encoders", to appear at NAACL 2019.
License: Other
Dear authors,
It seems the reported SEAT score of bert-large-cased
is wrong.
I was able to reproduce the results based on the current code base, however, I found two errors in the code.
import pytorch_pretrained_bert as bert
version = 'bert-large-cased'
tokenizer = bert.BertTokenizer.from_pretrained(version)
text = 'SEAT score of bert-large-CASED'
tokenized = tokenizer.tokenize(text) # ['seat', 'score', 'of', 'be', '##rt', '-', 'large', '-', 'case', '##d']
Below is the sentbias/encoders/bert.py
, and you can find text is not prepended with a [CLS]
token.
''' Convenience functions for handling BERT '''
import torch
import pytorch_pretrained_bert as bert
def load_model(version='bert-large-uncased'):
''' Load BERT model and corresponding tokenizer '''
tokenizer = bert.BertTokenizer.from_pretrained(version)
model = bert.BertModel.from_pretrained(version)
model.eval()
return model, tokenizer
def encode(model, tokenizer, texts):
''' Use tokenizer and model to encode texts '''
encs = {}
for text in texts:
tokenized = tokenizer.tokenize(text) # <<< BUG: a [CLS] token should be prepended
indexed = tokenizer.convert_tokens_to_ids(tokenized)
segment_idxs = [0] * len(tokenized)
tokens_tensor = torch.tensor([indexed])
segments_tensor = torch.tensor([segment_idxs])
enc, _ = model(tokens_tensor, segments_tensor, output_all_encoded_layers=False)
enc = enc[:, 0, :] # extract the last rep of the first input
encs[text] = enc.detach().view(-1).numpy()
return encs
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.