class_docstr: 条件随机场。提供 :meth:`forward` 以及 :meth:`viterbi_decode` 两个方法，分别用于 **训练** 与 **inference** 。
  
  :param num_tags: 标签的数量
  :param include_start_end_trans: 是否考虑各个 tag 作为开始以及结尾的分数。
  :param allowed_transitions: 内部的 ``Tuple[from_tag_id(int), to_tag_id(int)]`` 视为允许发生的跃迁，其他没
      有包含的跃迁认为是禁止跃迁，可以通过 :func:`allowed_transitions` 函数得到；如果为 ``None`` ，则所有跃迁均为合法。
class_docstr_tok: ["\u6761\u4ef6\u968f\u673a\u573a\u3002\u63d0\u4f9b",":","meth",":","`","forward","`","\u4ee5\u53ca",":","meth",":","`","viterbi_decode","`","\u4e24\u4e2a\u65b9\u6cd5\uff0c\u5206\u522b\u7528\u4e8e","*","*","\u8bad\u7ec3","*","*","\u4e0e","*","*","inference","*","*","\u3002",":","param","num_tags",":","\u6807\u7b7e\u7684\u6570\u91cf",":","param","include_start_end_trans",":","\u662f\u5426\u8003\u8651\u5404\u4e2a","tag","\u4f5c\u4e3a\u5f00\u59cb\u4ee5\u53ca\u7ed3\u5c3e\u7684\u5206\u6570\u3002",":","param","allowed_transitions",":","\u5185\u90e8\u7684","``","Tuple","[","from_tag_id","(","int",")",",","to_tag_id","(","int",")","]","``","\u89c6\u4e3a\u5141\u8bb8\u53d1\u751f\u7684\u8dc3\u8fc1\uff0c\u5176\u4ed6\u6ca1","\u6709\u5305\u542b\u7684\u8dc3\u8fc1\u8ba4\u4e3a\u662f\u7981\u6b62\u8dc3\u8fc1\uff0c\u53ef\u4ee5\u901a\u8fc7",":","func",":","`","allowed_transitions","`","\u51fd\u6570\u5f97\u5230\uff1b\u5982\u679c\u4e3a","``","None","``","\uff0c\u5219\u6240\u6709\u8dc3\u8fc1\u5747\u4e3a\u5408\u6cd5\u3002"]
docstr: Compute the score for the gold path.
  :param logits: FloatTensor, ``[max_len, batch_size, num_tags]``
  :param tags: LongTensor, ``[max_len, batch_size]``
  :param mask: ByteTensor, ``[max_len, batch_size]``
  :return:FloatTensor, ``[batch_size.]``
docstr_tok: ["Compute","the","score","for","the","gold","path",".",":","param","logits",":","FloatTensor",",","``","[","max_len",",","batch_size",",","num_tags","]","``",":","param","tags",":","LongTensor",",","``","[","max_len",",","batch_size","]","``",":","param","mask",":","ByteTensor",",","``","[","max_len",",","batch_size","]","``",":","return",":","FloatTensor",",","``","[","batch_size",".","]","``"]
code: def _gold_score(self, logits, tags, mask):
      r"""
      Compute the score for the gold path.
      :param logits: FloatTensor, ``[max_len, batch_size, num_tags]``
      :param tags: LongTensor, ``[max_len, batch_size]``
      :param mask: ByteTensor, ``[max_len, batch_size]``
      :return:FloatTensor, ``[batch_size.]``
      """
      seq_len, batch_size, _ = logits.size()
      batch_idx = torch.arange(
          batch_size, dtype=torch.long, device=logits.device
      )
      seq_idx = torch.arange(
          seq_len, dtype=torch.long, device=logits.device
      )
  
      # trans_socre [L-1, B]
      mask = mask.eq(True)
      flip_mask = mask.eq(False)
      trans_score = self.trans_m[
          tags[: seq_len - 1], tags[1:]
      ].masked_fill(flip_mask[1:, :], 0)
      # emit_score [L, B]
      emit_score = logits[
          seq_idx.view(-1, 1), batch_idx.view(1, -1), tags
      ].masked_fill(flip_mask, 0)
      # score [L-1, B]
      score = trans_score + emit_score[: seq_len - 1, :]
      score = score.sum(0) + emit_score[-1].masked_fill(
          flip_mask[-1], 0
      )
      if self.include_start_end_trans:
          st_scores = self.start_scores.view(1, -1).repeat(
              batch_size, 1
          )[batch_idx, tags[0]]
          last_idx = mask.long().sum(0) - 1
          ed_scores = self.end_scores.view(1, -1).repeat(batch_size, 1)[
              batch_idx, tags[last_idx, batch_idx]
          ]
          score = score + st_scores + ed_scores
      # return [B,]
      return score
  
file_path: fastNLP/fastNLP/modules/torch/decoder/crf.py
imports: from typing import Union, List, Tuple
  import torch
  from torch import nn
  from ....core.metrics.span_f1_pre_rec_metric import _get_encoding_type_from_tag_vocab, _check_tag_vocab_and_encoding_type
  from ....core.vocabulary import Vocabulary
label_desc: Use image node_id 3 for calling the ConditionalRandomField obj's underlying member method code with example usage: obj._gold_score(logits, tags, mask) and returns: score