juntaoy / biaffine-ner

Named Entity Recognition as Dependency Parsing
Apache License 2.0
347 stars 40 forks source link

about biaffine_ner_model.py #28

Open BinLingNie opened 3 years ago

BinLingNie commented 3 years ago

Hi, get_pred_ner() functions in your biaffine_ner_model.py

top_spans = [sorted(top_span,reverse=True,key=lambda x:x[3]) for top_span in top_spans]
sent_pred_mentions = [[] for _ in xrange(len(sentences))]
for sid, top_span in enumerate(top_spans):
  for ns,ne,t,_ in top_span:
    for ts,te,_ in sent_pred_mentions[sid]:
      if ns < ts <= ne < te or ts < ns <= te < ne:
        #for both nested and flat ner no clash is allowed
        break
      if is_flat_ner and (ns <= ts <= te <= ne or ts <= ns <= ne <= te):
        #for flat ner nested mentions are not allowed
        break
    else:
      sent_pred_mentions[sid].append((ns,ne,t))

According to the alignment of your codes, "else: sent_predmentions[sid].append((ns,ne,t))“ is aligned to "for ts,te, in sent_pred_mentions[sid]:". how to understand it ? "

juntaoy commented 3 years ago

The else here means the for loop finished without break. You can find more details about for/else in python here: https://book.pythontips.com/en/latest/for_-_else.html