本文整理汇总了Python中dataset.Dataset.get_slots方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.get_slots方法的具体用法?Python Dataset.get_slots怎么用?Python Dataset.get_slots使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dataset.Dataset
的用法示例。
在下文中一共展示了Dataset.get_slots方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_parse_iob
# 需要导入模块: from dataset import Dataset [as 别名]
# 或者: from dataset.Dataset import get_slots [as 别名]
def test_parse_iob(self):
test = 'i would like to go from (Columbia University)[from_stop] to (Herald Square)[to_stop]'
expected_iob = ['o', 'o', 'o', 'o', 'o', 'o', 'b-test.from_stop', 'i-test.from_stop', 'o', 'b-test.to_stop',
'i-test.to_stop']
expected_tokens = ['i', 'would', 'like', 'to', 'go', 'from', 'columbia', 'university', 'to', 'herald', 'square']
actual_iob, actual_tokens = Dataset.parse_iob('test', test)
self.assertEqual(actual_iob, expected_iob)
self.assertEqual(actual_tokens, expected_tokens)
for slot in set(expected_iob):
self.assertIn(slot, Dataset.get_slots())
示例2: open
# 需要导入模块: from dataset import Dataset [as 别名]
# 或者: from dataset.Dataset import get_slots [as 别名]
parser.add_argument('--slot')
parser.add_argument('dir')
args = parser.parse_args()
slots = []
files = os.listdir(args.slot)
for file in files:
if file.endswith('.slot'):
with open(os.path.join(args.slot, file), 'r', encoding='utf-8') as f:
slots += [slot.strip() for slot in f if len(slot.strip()) > 0]
Dataset.init_slot(set(slots))
vocab = Vocabulary('./word2vec.embeddings')
with tf.Session() as sess:
model = SlotTaggerModel(sess, vocab, Dataset.get_slots())
if args.mode == 'train':
train = []
dev = []
files = os.listdir(args.dir)
for file in files:
if file.endswith('.train'):
train += read_file(os.path.join(args.dir, file))
elif file.endswith('.dev'):
dev += read_file(os.path.join(args.dir, file))
train_dataset = Dataset.create_dataset(train)
dev_dataset = Dataset.create_dataset(dev)
print('Data size (train: %d, dev: %d)' % (train_dataset.length(), dev_dataset.length()))