d2l.Vocab(sentences, min_freq=5, reserved_tokens=[‘<pad>‘, ‘<mask>‘, ‘<cls>‘, ‘<sep>‘]) 参数讲解

69 篇文章 8 订阅
d2l.Vocab(sentences, min_freq=2, reserved_tokens=['<pad>', '<mask>', '<cls>', '<sep>'])
sentences:源句子,比如说 sentences赋值为下边的五个句子 注意第一句我手动添加了两个'<unk>',第二句添加了'<pad>', '<mask>', '<cls>', '<sep>',作为第三个参数的测试
[
	['<unk>', '<unk>', 'the', 'ottoman', 'turkish', 'empire', 'entered', 'the', 'first', 'world', 'war', 'on', 'the', 'side', 'of', 'the', 'central', 'powers', 'on', '31', 'october', '1914'], 
	['<pad>', '<mask>', '<cls>', '<sep>', 'the', 'stalemate', 'of', 'trench', 'warfare', 'on', 'the', 'western', 'front', 'convinced', 'the', 'british', 'imperial', 'war', 'cabinet', 'that', 'an', 'attack', 'on', 'the', 'central', 'powers', 'elsewhere', ',', 'particularly', 'turkey', ',', 'could', 'be', 'the', 'best', 'way', 'of', 'winning', 'the', 'war'], 
	['from', 'february', '1915', 'this', 'took', 'the', 'form', 'of', 'naval', 'operations', 'aimed', 'at', 'forcing', 'a', 'passage', 'through', 'the', 'dardanelles', ',', 'but', 'after', 'several', 'setbacks', 'it', 'was', 'decided', 'that', 'a', 'land', 'campaign', 'was', 'also', 'necessary'],
	['to', 'that', 'end', ',', 'the', 'mediterranean', 'expeditionary', 'force', 'was', 'formed', 'under', 'the', 'command', 'of', 'general', 'ian', 'hamilton'],
	['three', 'amphibious', 'landings', 'were', 'planned', 'to', 'secure', 'the', 'gallipoli', 'peninsula', ',', 'which', 'would', 'allow', 'the', 'navy', 'to', 'attack', 'the', 'turkish', 'capital', 'constantinople', ',', 'in', 'the', 'hope', 'that', 'would', 'convince', 'the', 'turks', 'to', 'ask', 'for', 'an', 'armistice', '.']
]
min_freq:把出现次数少于2次的低频率词元视为相同的未知词元即视为'<unk>'
reserved_tokens:如果遇到reserved_tokens中的词也作为token保留下来

一个完整的例子:
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值