text_helpers.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:TensorFlow-Machine-Learning-Cookbook 作者: PacktPublishing 项目源码 文件源码
def normalize_text(texts, stops):
    # Lower case
    texts = [x.lower() for x in texts]

    # Remove punctuation
    texts = [''.join(c for c in x if c not in string.punctuation) for x in texts]

    # Remove numbers
    texts = [''.join(c for c in x if c not in '0123456789') for x in texts]

    # Remove stopwords
    texts = [' '.join([word for word in x.split() if word not in (stops)]) for x in texts]

    # Trim extra whitespace
    texts = [' '.join(x.split()) for x in texts]

    return(texts)


# Build dictionary of words
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号