wanzhengzhu / gruen Goto Github PK
View Code? Open in Web Editor NEWGRUEN for Evaluating Linguistic Quality of Generated Text (EMNLP 2020 Findings)
Home Page: https://arxiv.org/pdf/2010.02498.pdf
License: MIT License
GRUEN for Evaluating Linguistic Quality of Generated Text (EMNLP 2020 Findings)
Home Page: https://arxiv.org/pdf/2010.02498.pdf
License: MIT License
Hi, I think the current implementation only covers three sub-scores: get_grammaticality_score, get_redundancy_score, get_focus_score. Where is the fourth function for evaluating Structure and coherence? Could you please let me know if I miss anything?
Hi,
I am using these amazing metric to evaluate text generated by a chatbot and I am not able to interpret the result of the output. Could you give some advice in the matter? What values are expected to be good and which one not?Thank you in advanced.
Focus score does not seem to be changing from 0, no matter what the candidate texts are.
It seems like it never runs this:
score.append(1.0 / (1.0 + math.exp(-sim + 7))) # score.append(1.0 / (1.0 + math.exp(-doc1.similarity(doc2) + 7)))
When trying to run on its own, I get the error: 'SpacySimilarityHook' object has no attribute 'similarity'
I noticed that the lm_score code processes a single sentence at a time. This is pretty slow if you're processing a large amount of data. I wrote a batched version, though it's a bit ugly. This increases processing speed by about 8x on a single 3090
import torch.nn.functional as F
def get_lm_score(sentences, batch_tokens=42000):
def score_batch(batch, tokenizer, model):
inputs = tokenizer(batch, padding=True, truncation=True, return_tensors="pt").to(device)
batch_scores = []
with torch.no_grad():
labels = inputs["input_ids"].clone()
labels[inputs["input_ids"] == tokenizer.pad_token_id] = -100
out = model(input_ids=inputs["input_ids"], labels=labels, attention_mask=inputs["attention_mask"], token_type_ids=inputs["token_type_ids"])
logits = out['logits']
for j in range(labels.shape[0]):
loss = F.cross_entropy(logits[j].view(-1, tokenizer.vocab_size), labels[j].view(-1))
batch_scores.append(math.exp(loss.item()))
return batch_scores
model_name = 'bert-base-cased'
model = BertForMaskedLM.from_pretrained(model_name).to(device)
model.eval()
tokenizer = BertTokenizerFast.from_pretrained(model_name)
lm_score = []
# sort sentences by length for optimal padding (getting the tokens takes too long so using string length as approximation)
sentences_flat = []
for sent in sentences:
for s in sent:
sentences_flat.append((s, len(s)))
sentences_flat.sort(key=lambda x: x[1], reverse=True)
batches = []
current_batch_count = 0
current_batch = []
for sent in sentences_flat:
current_batch.append(sent[0])
current_batch_count += sent[1]
if current_batch_count > batch_tokens:
batches.append(current_batch)
current_batch_count = 0
current_batch = []
if len(current_batch) > 0:
batches.append(current_batch)
score_dict = {}
for batch in tqdm(batches):
batch_score = score_batch(batch, tokenizer, model)
for j, sent in enumerate(batch):
score_dict[sent] = batch_score[j]
for sentence in sentences:
if len(sentence) == 0:
lm_score.append(0.0)
continue
score_i = 0.0
for x in sentence:
if x in score_dict:
score_i += score_dict[x]
else:
score_i += 10000
score_i /= len(sentence)
lm_score.append(score_i)
return lm_score
Hi, thanks for sharing this amazing project. I really like it.
The only problem that I find is that the fourth metric (Structure & Coherence) is not implemented in the code. Maybe you forget to add it?
It would be an incredible help if you could share it. :)
Thanks beforehand and have a nice weekend,
Victor
Any updates on the coherence score function? Can you push the code? Even if it's not too efficient now, we can try to improve.
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.