V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Braisdom
V2EX  ›  自然语言处理

请教一个 NLP 的问题

  •  1
     
  •   Braisdom · 2021-08-02 09:06:24 +08:00 · 3487 次点击
    这是一个创建于 969 天前的主题,其中的信息可能已经有所发展或是发生改变。

    请问一下大佬,有没有开源的组件可以提取短语的,例如:

    牛顿冷却定律在得到 APP 的实践背景介绍「得到锦囊」产品刚上线时,该版块首页的最热排序暴露了两个问题:分页时数据重复和最热榜单被霸屏,本文将围绕解决这两个问题来展开,介绍下如何参考牛顿冷却定律来优化最热内容的排序。“牛顿冷却定律”本质上它描述了高于周围温度的物体会向外散热,并逐渐降温的过程,同时单位时间内散热与周围温差会成正比关系。通过建立”温度”与”时间”之间的函数关系,构建一个”指数式衰减”( Exponential decay )的过程。如果我们把”热文排名”想象成一个”自然冷却”的过程,那么如下的场景是成立的:任一时刻,网站中所有的文章,都有一个”当前温度”,温度最高的文章就排在第一位。随着时间流逝,所有文章的温度都逐渐”冷却”。一、最热榜单暴露的问题 2020 年 1 月初,得到 App 的新产品「得到锦囊」正式上线。产品刚上线时,版块首页的最热排序模块,暴露出了两个问题:分页时数据重复和最热榜单被霸屏,本文将围绕解决这两个问题来展开。排序规则与朴素的实现方案产品需求定义的最热排序规则是:按照问题的总查看量来倒序排列,且有分页和查询条件。服务端对于这种场景,最简单高效的实现方式,就是利用 sql 的 query 语句了,于是我们就直接 [order by {问题的查看量} desc] 来实现了。总查看数 = 获得查看权益的用户数 = 购买数 + 赠一得一领取数这个简单朴素的实现方式,在加上缓存策略,使得我们用较小的成本就满足了产品需求,也应对了较高的流量。
    

    如上述语句,可以提取出:“牛顿冷却定律”,“得到锦囊”,“热榜单霸屏” 等短语,感谢。

    22 条回复    2023-08-29 10:37:44 +08:00
    shengchen11
        1
    shengchen11  
       2021-08-02 10:44:06 +08:00
    Braisdom
        2
    Braisdom  
    OP
       2021-08-02 11:08:44 +08:00
    @shengchen11 这个只能分词呀。
    Morriaty
        3
    Morriaty  
       2021-08-02 11:13:53 +08:00
    @Braisdom #2 from jieba.analyse import extract_tags,不过你别指望提取的效果能有多好🐶
    2dot71828
        4
    2dot71828  
       2021-08-02 11:18:21 +08:00
    @Braisdom 你提取特定词只是在分词基础上的白名单吧...
    murmur
        5
    murmur  
       2021-08-02 11:24:01 +08:00
    以前类似东西叫命名实体识别,实际上所谓的 AI 都是靠人,你这一堆东西我自己看都不靠谱,NLP 能干嘛

    单一文章是没法造词的,得热,得权威,两个有一个才可以造词
    xingshu1990
        6
    xingshu1990  
       2021-08-02 11:24:23 +08:00
    百度搜索了一下 python 分词 ,看了一下 python TF IDF 执行的内容,包括题主说的关键词,只不过还加载自己训练过的词库,所以分词还没准确。
    xingshu1990
        7
    xingshu1990  
       2021-08-02 11:28:28 +08:00
    @xingshu1990 错了 搜索关键词是:python 提取关键词 中间涉及到的是 textrank tf-idf (还有一种是 TF IWF ) LDA
    Braisdom
        8
    Braisdom  
    OP
       2021-08-02 13:42:58 +08:00
    @xingshu1990 textrank, pagerank, positionrank 我都试过了,英文的还行,中文的比较差。下面是我根据句法分析得出的结果:
    ```
    ['牛顿冷却定律', '在', '得到', ' ', 'APP', ' ', '的', '实践', '背景', '介绍', '「', '得到', '锦囊', '」', '产品', '刚', '上线', '时', ',', '该', '版块', '首页', '的', '最', '热', '排序', '暴露', '了', '两个', '问题', ':', '分页', '时', '数据', '重复', '和', '最', '热', '榜单', '被', '霸屏', ',', '本文', '将', '围绕', '解决', '这', '两个', '问题', '来', '展开', ',', '介绍', '下', '如何', '参考', '牛顿冷却定律', '来', '优化', '最', '热', '内容', '的', '排序', '。', '“', '牛顿冷却定律', '”', '本质', '上', '它', '描述', '了', '高于', '周围', '温度', '的', '物体', '会', '向外', '散热', ',', '并', '逐渐', '降温', '的', '过程', ',', '同时', '单位', '时间', '内', '散热', '与', '周围', '温差', '会', '成正比', '关系', '。', '通过', '建立', '”', '温度', '”', '与', '”', '时间', '”', '之间', '的', '函数', '关系', ',', '构建', '一个', '”', '指数式衰减', '”', '(', ' ', 'Exponential decay', ' ', ')', '的', '过程', '。', '如果', '我们', '把', '”', '热文', '排名', '”', '想象', '成', '一个', '”', '自然', '冷却', '”', '的', '过程', ',', '那么', '如下', '的', '场景', '是', '成立', '的', ':', '任一', '时刻', ',', '网站', '中', '所有', '的', '文章', ',', '都', '有', '一个', '”', '当前', '温度', '”', ',', '温度', '最高', '的', '文章', '就', '排', '在', '第一位', '。', '随着', '时间', '流逝', ',', '所有', '文章', '的', '温度', '都', '逐渐', '”', '冷却', '”', '。', '一', '、', '最', '热', '榜单', '暴露', '的', '问题', ' ', '2020', ' ', '年', ' ', '1', ' ', '月初', ',', '得到', ' ', 'App', ' ', '的', '新产品', '「', '得到', '锦囊', '」', '正式', '上线', '。', '产品', '刚', '上线', '时', ',', '版块', '首页', '的', '最', '热', '排序', '模块', ',', '暴露', '出', '了', '两个', '问题', ':', '分页', '时', '数据', '重复', '和', '最', '热', '榜单', '被', '霸屏', ',', '本文', '将', '围绕', '解决', '这', '两个', '问题', '来', '展开', '。', '排序', '规则', '与', '朴素', '的', '实现', '方案', '产品', '需求', '定义', '的', '最', '热', '排序', '规则', '是', ':', '按照', '问题', '的', '总', '查看', '量', '来倒序排列', ',', '且', '有', '分页', '和', '查询', '条件', '。', '服务端', '对于', '这种', '场景', ',', '最', '简单', '高效', '的', '实现', '方式', ',', '就是', '利用', ' ', 'sql', ' ', '的', ' ', 'query', ' ', '语句', '了', ',', '于是', '我们', '就', '直接', ' ', '[', 'order by', ' ', '{', '问题', '的', '查看', '量', '}', ' ', 'desc', ']', ' ', '来', '实现', '了', '。', '总', '查看', '数', ' ', '=', ' ', '获得', '查看', '权益', '的', '用户数', ' ', '=', ' ', '购买', '数', ' ', '+', ' ', '赠一得', '一', '领取', '数', '这个', '简单', '朴素', '的', '实现', '方式', ',', '在', '加上', '缓存', '策略', ',', '使得', '我们', '用', '较小', '的', '成本', '就', '满足', '了', '产品', '需求', ',', '也', '应对', '了', '较高', '的', '流量', '。']
    ['nz', 'd', 'v', 'w', 'nz', 'w', 'u', 'vn', 'n', 'v', 'w', 'v', 'n', 'w', 'n', 'd', 'v', 'n', 'w', 'r', 'q', 'n', 'u', 'd', 'a', 'vn', 'v', 'u', 'm', 'n', 'w', 'v', 'n', 'n', 'vn', 'c', 'd', 'a', 'n', 'p', 'n', 'w', 'n', 'd', 'v', 'v', 'r', 'm', 'n', 'v', 'v', 'w', 'v', 'q', 'r', 'v', 'nz', 'v', 'v', 'd', 'a', 'n', 'u', 'vn', 'w', 'w', 'nz', 'w', 'n', 'f', 'r', 'v', 'u', 'v', 'f', 'n', 'u', 'n', 'v', 'd', 'v', 'w', 'c', 'd', 'v', 'u', 'n', 'w', 'd', 'n', 'n', 'f', 'v', 'p', 'f', 'n', 'v', 'v', 'n', 'w', 'p', 'v', 'w', 'n', 'w', 'c', 'w', 'n', 'w', 'f', 'u', 'n', 'n', 'w', 'v', 'm', 'w', 'nz', 'w', 'w', 'w', 'ORG', 'w', 'w', 'u', 'n', 'w', 'c', 'r', 'p', 'w', 'n', 'vn', 'w', 'v', 'v', 'm', 'w', 'ad', 'v', 'w', 'u', 'n', 'w', 'c', 'v', 'u', 'n', 'v', 'v', 'u', 'w', 'r', 'n', 'w', 'n', 'f', 'r', 'u', 'n', 'w', 'd', 'v', 'm', 'w', 'TIME', 'n', 'w', 'w', 'n', 'a', 'u', 'n', 'd', 'v', 'p', 'm', 'w', 'p', 'n', 'v', 'w', 'a', 'n', 'u', 'n', 'd', 'd', 'w', 'v', 'w', 'w', 'm', 'w', 'd', 'a', 'n', 'v', 'u', 'n', 'w', 'm', 'w', 'q', 'w', 'm', 'w', 'TIME', 'w', 'v', 'w', 'nz', 'w', 'u', 'n', 'w', 'v', 'n', 'w', 'ad', 'v', 'w', 'n', 'd', 'v', 'n', 'w', 'n', 'n', 'u', 'd', 'a', 'vn', 'n', 'w', 'v', 'v', 'u', 'm', 'n', 'w', 'v', 'n', 'n', 'vn', 'c', 'd', 'a', 'n', 'p', 'n', 'w', 'n', 'd', 'v', 'v', 'r', 'm', 'n', 'v', 'v', 'w', 'vn', 'n', 'c', 'a', 'u', 'vn', 'n', 'n', 'n', 'v', 'u', 'd', 'a', 'vn', 'n', 'v', 'w', 'p', 'n', 'u', 'a', 'vn', 'n', 'v', 'w', 'c', 'v', 'vn', 'c', 'vn', 'n', 'w', 'n', 'p', 'r', 'n', 'w', 'd', 'a', 'a', 'u', 'vn', 'n', 'w', 'v', 'v', 'w', 'n', 'w', 'u', 'w', 'nz', 'w', 'n', 'xc', 'w', 'c', 'r', 'd', 'ad', 'w', 'w', 'nz', 'w', 'w', 'n', 'u', 'vn', 'n', 'w', 'w', 'n', 'w', 'w', 'v', 'v', 'u', 'w', 'd', 'v', 'n', 'w', 'w', 'w', 'v', 'v', 'n', 'u', 'n', 'w', 'w', 'w', 'v', 'n', 'w', 'w', 'w', 'v', 'm', 'v', 'n', 'r', 'a', 'a', 'u', 'vn', 'n', 'w', 'p', 'v', 'vn', 'n', 'w', 'v', 'r', 'p', 'a', 'u', 'n', 'd', 'v', 'u', 'n', 'n', 'w', 'd', 'v', 'u', 'a', 'u', 'n', 'w']
    细粒度: [(('牛顿冷却定律', '在'), 'ADV_V'), ((None, '得到', 'APP'), 'SVO'), (('得到', '背景'), 'ATT_N'), (('实践', '背景'), 'ATT_N'), (('背景', '介绍'), 'ATT_N'), ((None, '得到', '锦囊'), 'SVO'), ((None, '得到', '上线'), 'SVO'), (('介绍', '得到'), 'ATT_N'), (('产品', '上线', None), 'SVO'), (('刚', '上线'), 'ADV_V'), (('得到', '时'), 'ATT_N'), (('该', '版块'), 'ATT_N'), (('版块', '首页'), 'ATT_N'), (('最', '热'), 'ADV_V'), (('首页', '排序'), 'ATT_N'), (('热', '排序'), 'ATT_N'), (('排序', '暴露', '问题'), 'SVO'), (('时', '暴露'), 'ADV_V'), (('两个', '问题'), 'ATT_N'), (('分页', '时'), 'ATT_N'), (('时', '重复'), 'ADV_V'), (('时', '霸屏'), 'ADV_V'), (('数据', '重复'), 'ATT_N'), (('数据', '霸屏'), 'ATT_N'), (('霸屏',), 'Phrase'), (('最', '热'), 'ADV_V'), (('热', '榜单'), 'ATT_N'), ((None, '霸屏', '榜单'), 'SVO'), ((None, '围绕', '解决'), 'SVO'), ((None, '解决', '问题'), 'SVO'), (('这', '问题'), 'ATT_N'), (('两个', '问题'), 'ATT_N'),...
    ```
    Braisdom
        9
    Braisdom  
    OP
       2021-08-02 13:44:34 +08:00
    词性、还可以,句法分析就差太多了,我在想是不是自己按词性进行组合,单纯分析词性,同义词比较差,只能结合句法分析,
    Braisdom
        10
    Braisdom  
    OP
       2021-08-02 13:46:00 +08:00
    @shengchen11
    @Morriaty
    @2dot71828
    @murmur
    有没有根据词性的正则表达式,匹配短语的工具,我找了好久没找到。
    zyx199199
        11
    zyx199199  
       2021-08-02 13:55:30 +08:00
    @Braisdom 可以用 spacy,外国的全能 NLP 工具,支持中文

    可以参考这个 https://spacy.io/usage/rule-based-matching 文档,可以根据各种条件进行正则匹配,当然也支持词性匹配
    Braisdom
        12
    Braisdom  
    OP
       2021-08-02 14:00:24 +08:00
    @zyx199199 感谢,我用 spacy 做英文短语挖掘还行,中文的太弱了
    原文:
    ```
    ObjectiveSQL is an ORM framework in Java based on ActiveRecord pattern, which encourages rapid development and clean, codes with the least and convention over configuration.
    If your project focuses on data analysis based on relation database, and a lot of arithmetic expressions in SQL statement. ObjectiveSQL will help you write expressions conveniently and safely using Java syntax
    ```
    解析结果:
    ```
    0.1476792292949645 1 activerecord pattern
    0.14671762416303413 1 java syntax
    0.14428737286880544 1 rapid development
    0.13810946085925754 1 configuration
    0.1346420067987634 3 java
    0.1256596948856068 4 objectivesql
    0.11204090834509414 1 activerecord
    0.11121633331630836 1 orm
    0.10988850573204359 1 convention
    0.10555338794853333 1 codes
    0.09950835257874349 1 sql statement
    0.09622020612487797 1 arithmetic expressions
    0.0881090251048002 1 relation database
    0.08001718286200812 1 an orm framework
    0.07570218212468754 1 expressions
    0.06679224022078173 1 sql
    0.05478959497093751 1 data analysis
    0.03418629755285734 1 a lot
    0.014509931733698266 1 your project
    0.0 1 you
    0.036164045333862305
    ```
    yzc27
        13
    yzc27  
       2021-08-02 14:07:36 +08:00
    NER(命名实体识别),用 bert 训练试下。不过前提肯定是要有已经标注好的训练数据。
    demobin
        14
    demobin  
       2021-08-02 18:07:38 +08:00
    你们不是做 nlp 的 所以不了解吧 太多了
    哈工大的 http://ltp.ai/demo.html
    百度的 https://nlp.baidu.com/homepage/index
    腾讯的 https://cloud.tencent.com/product/nlp
    https://texsmart.qq.com/zh
    开源的 hanlp https://github.com/hankcs/HanLP
    甚至我自己都开发过一套基于 dl 的 pipeline
    但是 要说效果 那真的 没有一家你会满意 因为 nlp 现在就是这么垃圾 否则也不会被称为 人工智能皇冠上的明珠了
    Braisdom
        15
    Braisdom  
    OP
       2021-08-02 18:13:47 +08:00
    感谢各位,通过句法分析,得出的词性相对较好一点,尤其是同义词,在句法分析中比较容易区分,纯粹的词性标注,结果太差了,找到一个开源工具,可以根据词性提取短语。

    https://github.com/chartbeat-labs/textacy

    有兴趣的可以看看,刚刚试了一下还行,还在测试中。
    Braisdom
        16
    Braisdom  
    OP
       2021-08-02 18:23:59 +08:00
    测试了一下,效果不错:

    '''
    Text summarization is one of the newest and most exciting fields in NLP, allowing for developers to quickly find meaning and extract key words and phrases from documents. RaRe Technologies’ newest intern, Ólavur Mortensen, walks the user through text summarization features in Gensim.
    '''

    这样的一段英文,解析出来的结果:

    Text summarization
    exciting fields
    key words
    newest intern
    text summarization
    text summarization features
    summarization features

    takes: 0.019918203353881836
    Braisdom
        17
    Braisdom  
    OP
       2021-08-02 20:21:43 +08:00
    调整了一下,非常完善的英文短语提取:

    ```
    Software engineering is one of the most popular branches of computer science and has taken over the world in the digitization era. Software engineers are required in almost every field these days. With the easy accessibility of computers and smartphones, the importance of software engineering has become more pronounced.
    Since software engineering is an advanced field of the IT industry, there are very few institutes that offer bachelor courses in this field. One can pursue B.Tech in CSE or IT and go on to pursue M.Tech in software engineering. Aspiring software engineers can find all about the courses and eligibility criteria below.
    About Software Engineering:
    Software engineering is a branch of computer science engineering (CSE), therefore, there are very few colleges that offer software engineering bachelor degree. Most of the institutes in India provide software engineering specialization at the masters’ level.
    M.Tech in software engineering is one of the most popular courses amongst computer science engineers. You can prepare for GATE exam and apply for these courses through GATE score.
    The courses cover advanced software development models and programming concepts that are the elementary parts of developing software. Software engineering also comprises the study of the different levels of the software development process.
    Eligibility Criteria for Software Engineering:
    ```

    提取的短语如下:

    ```
    Software engineering
    branches of computer
    branches of computer science
    computer science
    digitization era
    Software engineers
    accessibility of computers
    importance of software
    importance of software engineering
    software engineering
    software engineering
    bachelor courses
    software engineering
    software engineers
    branch of computer
    branch of computer science
    computer science
    branch of computer science engineering
    computer science engineering
    science engineering
    software engineering
    software engineering bachelor
    engineering bachelor
    software engineering bachelor degree
    engineering bachelor degree
    bachelor degree
    software engineering
    software engineering specialization
    engineering specialization
    software engineering
    courses amongst computer
    courses amongst computer science
    computer science
    courses amongst computer science engineers
    computer science engineers
    science engineers
    software development
    software development models
    development models
    programming concepts
    Software engineering
    software development
    software development process
    development process

    takes: 0.05262303352355957
    ```
    heqing
        18
    heqing  
       2021-08-02 22:41:08 +08:00
    可以试一下这个, https://github.com/thunlp/BERT-KPE
    Braisdom
        19
    Braisdom  
    OP
       2021-08-03 10:06:29 +08:00
    测试了一下,中文处理也非常不错,spacy 的中文分词不是特别理想,需要补充,但基本可用。

    测试文本:
    ```
    DDParser 是百度自然语言处理部基于大规模标注数据研发的依存句法分析工具。其训练数据不仅覆盖了多种输入形式的数据,如键盘输入 query 、语音输入 query 等,还覆盖了多种场景的数据,如新闻、论坛等。该工具易用性高,支持一键安装及预测。
    ```

    解析出的短语如下:
    ```
    百度
    百度自然
    百度自然语言
    自然语言
    百度自然语言处理部
    自然语言处理部
    语言处理部
    数据研发
    依存句法
    句法分析
    依存句法分析
    句法分析工具
    分析工具
    依存句法分析工具
    训练数据
    多种输入
    输入形式
    多种输入形式
    多种场景
    易用性
    键安装
    ```
    rpman
        20
    rpman  
       2021-08-30 12:05:21 +08:00
    @Braisdom 你想找的是一个符合你期待的 NER(命名实体识别)或者 KPE(关键词抽取)
    但这种东西。。你不用数据来训模型,怎么能让模型符合你的期待呢
    Braisdom
        21
    Braisdom  
    OP
       2021-09-01 22:00:27 +08:00
    @rpman 我已经找到方法了,但不是特别理想,我并不是想要找到实现,短语的组合也很多,穷举也很累。
    qsnow6
        22
    qsnow6  
       212 天前
    @Braisdom #21 OP 主的实现方案是什么
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2699 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 15:34 · PVG 23:34 · LAX 08:34 · JFK 11:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.