随机创建训练集和测试集合的方法

2018-12-22  本文已影响5人  VanJordan
MyTupleClass = collections.namedtuple('MyTupleClass',['name', 'age', 'job'])
obj = MyTupleClass("Tomsom",12,'Cooker')
print(obj.name)
print(obj.age)
print(obj.job)
>>Tomsom
12
Cooker
Document = namedtuple('Document',
                      'content is_validation is_test label add_tokens')

random_int = random.randint(1, 10)
is_validation = random_int == 1
is_test = random_int == 2
if (is_test and dataset != 'test') or (is_validation and
                                       not include_validation):
    continue

yield Document(
    content=content,
    is_validation=is_validation,
    is_test=is_test,
    label=class_label,
    add_tokens=True)
上一篇下一篇

猜你喜欢

热点阅读