当前位置: 首页>>代码示例>>Python>>正文


Python check.NotIn方法代码示例

本文整理汇总了Python中syntaxnet.util.check.NotIn方法的典型用法代码示例。如果您正苦于以下问题:Python check.NotIn方法的具体用法?Python check.NotIn怎么用?Python check.NotIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在syntaxnet.util.check的用法示例。


在下文中一共展示了check.NotIn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testCheckNotIn

# 需要导入模块: from syntaxnet.util import check [as 别名]
# 或者: from syntaxnet.util.check import NotIn [as 别名]
def testCheckNotIn(self):
    check.NotIn('d', ('a', 'b', 'c'), 'foo')
    check.NotIn('c', {'a': 1, 'b': 2}, 'bar')
    with self.assertRaisesRegexp(ValueError, 'bar'):
      check.NotIn('a', ('a', 'b', 'c'), 'bar')
    with self.assertRaisesRegexp(RuntimeError, 'baz'):
      check.NotIn('b', {'a': 1, 'b': 2}, 'baz', RuntimeError) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:9,代码来源:check_test.py

示例2: calculate_segmentation_metrics

# 需要导入模块: from syntaxnet.util import check [as 别名]
# 或者: from syntaxnet.util.check import NotIn [as 别名]
def calculate_segmentation_metrics(gold_corpus, annotated_corpus):
  """Calculate precision/recall/f1 based on gold and annotated sentences."""
  check.Eq(len(gold_corpus), len(annotated_corpus), 'Corpora are not aligned')
  num_gold_tokens = 0
  num_test_tokens = 0
  num_correct_tokens = 0
  def token_span(token):
    check.Ge(token.end, token.start)
    return (token.start, token.end)

  def ratio(numerator, denominator):
    check.Ge(numerator, 0)
    check.Ge(denominator, 0)
    if denominator > 0:
      return numerator / denominator
    elif numerator == 0:
      return 0.0  # map 0/0 to 0
    else:
      return float('inf')  # map x/0 to inf

  for gold_str, annotated_str in zip(gold_corpus, annotated_corpus):
    gold = sentence_pb2.Sentence()
    annotated = sentence_pb2.Sentence()
    gold.ParseFromString(gold_str)
    annotated.ParseFromString(annotated_str)
    check.Eq(gold.text, annotated.text, 'Text is not aligned')
    gold_spans = set()
    test_spans = set()
    for token in gold.token:
      check.NotIn(token_span(token), gold_spans, 'Duplicate token')
      gold_spans.add(token_span(token))
    for token in annotated.token:
      check.NotIn(token_span(token), test_spans, 'Duplicate token')
      test_spans.add(token_span(token))
    num_gold_tokens += len(gold_spans)
    num_test_tokens += len(test_spans)
    num_correct_tokens += len(gold_spans.intersection(test_spans))

  tf.logging.info('Total num documents: %d', len(annotated_corpus))
  tf.logging.info('Total gold tokens: %d', num_gold_tokens)
  tf.logging.info('Total test tokens: %d', num_test_tokens)
  precision = 100 * ratio(num_correct_tokens, num_test_tokens)
  recall = 100 * ratio(num_correct_tokens, num_gold_tokens)
  f1 = ratio(2 * precision * recall, precision + recall)
  tf.logging.info('Precision: %.2f%%', precision)
  tf.logging.info('Recall: %.2f%%', recall)
  tf.logging.info('F1: %.2f%%', f1)

  return round(precision, 2), round(recall, 2), round(f1, 2) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:51,代码来源:evaluation.py


注:本文中的syntaxnet.util.check.NotIn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。