本文整理匯總了Python中allennlp.data.dataset_readers.dataset_reader.DatasetReader方法的典型用法代碼示例。如果您正苦於以下問題:Python dataset_reader.DatasetReader方法的具體用法?Python dataset_reader.DatasetReader怎麽用?Python dataset_reader.DatasetReader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類allennlp.data.dataset_readers.dataset_reader
的用法示例。
在下文中一共展示了dataset_reader.DatasetReader方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from allennlp.data.dataset_readers import dataset_reader [as 別名]
# 或者: from allennlp.data.dataset_readers.dataset_reader import DatasetReader [as 別名]
def __init__(self, model: Model, dataset_reader: DatasetReader) -> None:
super().__init__(model, dataset_reader)
# Due to a formatting issue, the word overlap model includes the newline character in the
# label string. So we first create a map from the stripped label to the model label and
# then use the model label to get the index of entailment class. It is designed in this
# manner to also automatically handle any new models that do not have this bug.
labels = {label.strip(): label
for label in self._model.vocab.get_index_to_token_vocabulary("labels").values()}
if "entails" in labels:
self._entailment_idx = self._model.vocab.get_token_index(labels["entails"], "labels")
elif "entailment" in labels:
self._entailment_idx = self._model.vocab.get_token_index(labels["entailment"], "labels")
else:
raise Exception("No label for entailment found in the label space: {}".format(
",".join(labels)))
示例2: __init__
# 需要導入模塊: from allennlp.data.dataset_readers import dataset_reader [as 別名]
# 或者: from allennlp.data.dataset_readers.dataset_reader import DatasetReader [as 別名]
def __init__(self, model: Model, dataset_reader: DatasetReader) -> None:
super().__init__(model, dataset_reader)
labels = self._model.vocab.get_index_to_token_vocabulary("labels").values()
#
if "entails" in labels:
self._entailment_idx = self._model.vocab.get_token_index("entails", "labels")
elif "entailment" in labels:
self._entailment_idx = self._model.vocab.get_token_index("entailment", "labels")
else:
raise Exception("No label for entailment found in the label space: {}".format(
",".join(labels)))
示例3: __init__
# 需要導入模塊: from allennlp.data.dataset_readers import dataset_reader [as 別名]
# 或者: from allennlp.data.dataset_readers.dataset_reader import DatasetReader [as 別名]
def __init__(self, model: Model, dataset_reader: DatasetReader) -> None:
super().__init__(model, dataset_reader)
self._stemmer = PorterStemmer()
self._stop_words = set(stopwords.words('english'))