请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

老师,我不太明白这个k:(v+3)的意思

老师,你好,我不太明白这个v+3是什么意思,v在这里是value,是数字对吧?k是Key(是word).那么k+3是什么意思呢?可否给我一个比方?我看了您有回答别的同学的答案,说是‘’取出来的词表还是从1开始的,需要做处理”,我还是不明白这个意思。。
图片描述

正在回答

插入代码

1回答

在取出word_index后,你可以按照value排序一下,然后打印前100个。

1
2
3
4
word_index = imdb.get_word_index()
print(len(word_index))
sorted_word_index = sorted(word_index.items(), key = lambda d:d[1])
print(sorted_word_index[0:100])

得到的结果是:

1
[('the'1), ('and'2), ('a'3), ('of'4), ('to'5), ('is'6), ('br'7), ('in'8), ('it'9), ('i'10), ('this'11), ('that'12), ('was'13), ('as'14), ('for'15), ('with'16), ('movie'17), ('but'18), ('film'19), ('on'20), ('not'21), ('you'22), ('are'23), ('his'24), ('have'25), ('he'26), ('be'27), ('one'28), ('all'29), ('at'30), ('by'31), ('an'32), ('they'33), ('who'34), ('so'35), ('from'36), ('like'37), ('her'38), ('or'39), ('just'40), ('about'41), ("it's"42), ('out', 43), ('has', 44), ('if', 45), ('some', 46), ('there', 47), ('what', 48), ('good', 49), ('more', 50), ('when', 51), ('very', 52), ('up', 53), ('no', 54), ('time', 55), ('she', 56), ('even', 57), ('my', 58), ('would', 59), ('which', 60), ('only', 61), ('story', 62), ('really', 63), ('see', 64), ('their', 65), ('had', 66), ('can', 67), ('were', 68), ('me', 69), ('well', 70), ('than', 71), ('we', 72), ('much', 73), ('been', 74), ('bad', 75), ('get', 76), ('will', 77), ('do', 78), ('also', 79), ('into', 80), ('people', 81), ('other', 82), ('first', 83), ('great', 84), ('because', 85), ('how', 86), ('him', 87), ('most', 88), ("don't", 89), ('made'90), ('its'91), ('then'92), ('way'93), ('make'94), ('them'95), ('too'96), ('could'97), ('any'98), ('movies'99), ('after'100)]

然后发现,index还是从1开始的,而我们要对0,1,2,3设置其他字符,所以要让the的value是4, and的value是5,以此类推。

0 回复 有任何疑惑可以回复我~
  • 提问者 慕尼黑0536602 #1
    好的,谢谢老师,明白了
    回复 有任何疑惑可以回复我~ 2020-03-24 21:53:00
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信