← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 6669.b · 生成模型:GPT-6

字符分析器仍有独立配置边界

理解等级:中级

按字符列表作自定义tokenizer,需明确大小写、空白、标点与停用项规则,并保持特征编号一致。批量结果的toarray()[0]只选第一篇,不能把它当整个批量已处理;调试时应同时检查输入文档数和输出行数。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • · 查看原书依据

      >>> from string import punctuation >>> punc = list(punctuation) + list(' \n') >>> def count_chars(text, tokenizer=list, token_pattern=None, ... stop_words=punc, **kwargs): ... lot = [text] if isinstance(text, str) else text #1 ... vectorizer = CountVectorizer( ... token_pattern=token_pattern, ... stop_words=stop_words, ... tokenizer=tokenizer, #2 ... **kwargs) ... counts = vectorizer.fit_transform(lot) #3 ... counts = counts.toarray()[0] #4 ... vocab = vectorizer.vocabulary_ ... index = pd.Series(vocab).sort_values().index ... counts = pd.Series(counts,

    参考来源

    - 位置:《Natural Language Processing in Action, Second Edition》第03章《词频与逆文档频率向量》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Natural Language Processing in Action, Second Edition/_epub-src/OEBPS/Text/chapter-3.html) - 结论依据:摘录中关于字符分析器仍有独立配置边界的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。 - 原始内容:>>> from string import punctuation >>> punc = list(punctuation) + list(' \n') >>> def count_chars(text, tokenizer=list, token_pattern=None, ... stop_words=punc, **kwargs): ... lot = [text] if isinstance(text, str) else text #1 ... vectorizer = CountVectorizer( ... token_pattern=token_pattern, ... stop_words=stop_words, ... tokenizer=tokenizer, #2 ... **kwargs) ... counts = vectorizer.fit_transform(lot) #3 ... counts = counts.toarray()[0] #4 ... vocab = vectorizer.vocabulary_ ... index = pd.Series(vocab).sort_values().index ... counts = pd.Series(counts,