Natural Language Processing NLP

NLP

清晰版本查看

  • Sentence segmentation (split)
  • Tokenisation (split)
  • Named entity recognition (combine)
概念主要內容典型方法
Distributional Semantics(分佈式語義)(分銷語義(分佈式語義)單詞的語義來自於它的上下文共現矩陣(Co-occurrence Matrix),PMI共現矩陣(共發生矩陣Chesi
Word Embeddings(詞嵌入)變成嵌入(詞嵌入)將單詞映射到低維向量空間,以捕捉語義關係Word2Vec、GloVe、FastText、BERTword2vec,手套,fasttx,bere
Word Sense Disambiguation(詞義消歧)單詞感官歧義(詞義消歧)根據語境確定詞的正確含義WordNet、機器學習、BERT

introduction to NLP

A research field focussed on creating software systems with knowledge about natural (human) language 研究重點是關於自認語言的知識

Interdisciplinary: makes use of theories from Linguistics 語言學理論, adopts an Engineering approach

Aimed at human-like understanding of language (but not yet there)

[!tip] Contributing disciplines
Linguistics: formal models of language, linguistic knowledge
Computer Science: representations, efficient processing, state machines, parsing
algorithms, probabilistic models, dynamic programming, machine learning
Mathematics: formal automata theory, computational modelling
Psychology: psychologically plausible modelling of language use

Many types of ambiguity歧義:

  • Phonological 語音學
    • multiple interpretations due to how it sounds 有些音聽起來一樣 那麼在識別的時候會存在很多種解釋
  • Lexical 詞匯
    • multiple interpretations due to a word having multiple senses 詞語的歧義,由於有的單詞本身帶有的意思多重導致的
  • Syntactic 句法
    • due to a word having more than one possible part of speech 一個單詞有多個演講部分
    • due to prepositional phrase attachment 介詞的附件
  • Semantic 語義
    • multiple possible interpretations解釋 unless knowledge of the world is available

[!danger] Two major approaches to NLP

  • Symbolic 象征
    • Rule- and dictionary-based systems 基於規則和字典系統
    • Captures linguistic knowledge in rules written by experts 補貨專家撰寫的規則中的語言知識
  • Statistical/Machine learning-based
    • Data-driven 數據驅動
    • Use of large amounts of (labelled) textual data (文本數據) to train systems, discover patterns

Comparison

SymbolicStatistical/Machine learning
✅  Expert knowledge yields highly precise results 專業知識會產生高度精確的結果✅Can generalise well on unseen examples可以很好的概括在看不見的例子上
Shortage of experts❎Need people for labelling
❎Laborious rule writing, dictionary preparation❎Time consuming and laborious labelling 耗時且費力
❎ Domain adaptation problematic域適應性問題❎Must retrain for new domain必須重新訓練
✅Results can be interpreted結果可以解釋❎ Often cannot inspect/change models通常無法檢查/更改模型
✅  Good when labelled data is hard to obtain當很難獲得標記的數據時✅ Good where dictionaries are unavailable

NLP Pipelines

A ‘complete’ NLP system is usually a pipeline of components

在这里插入图片描述

  • Sentence Segmentation 句子細分
  • Tokenisation 象征化
  • Parsing
  • Information

在这里插入图片描述


  • Sentence segmentation (split)
  • Tokenisation (split)
  • Named entity recognition (combine)

Why is NLP challenging:

  • Natural Language evolve:
    • new words appear constantly
    • Syntactic rules are flexible 句法規則靈活
    • ambiguity (模糊性) is inherent 固有的

Why Machine Learning for NLP

  • Traditional rule-based artificial intelligence (symbolic AI):
    • requires expert knowledge to engineer the rules 需要專家知識來設計
    • not flexible to adapt in multiple languages, domains, applications 不能靈活低使用與多種語言
  • Learning from data (machine learning) adapts:
    • to evolution: just learn from new data 從新數據中學習
    • to different applications: just learn with the appropriate target representation

Sentence Segmentation 句子細分

Sentence Detection is done before the text is tokenized 句子檢測在文本標記化之前進行

Task 順序:

  • Determination of boundaries between sentences確定句子之間的界限
  • Sentences used in subsequent NLP tasks 隨後NLP中使用的句子
  • Is it enough to detect the full stop
    • Could be an end-of-sentence (EOS) marker 可能是句子結束 (EOS) 標記
    • Or an end of abbreviation marker 縮寫標記的結尾
    • Or both

通常是Text Mining的第一步,因為它將非結構化文本拆分成基本處理單位

Variation in delimiters

  • Typical:“.”,“!”,“?”

[!todo] # Approaches

  • Regular expressions (Patterns) 正則表達式
  • Dictionaries (e.g., abbreviation lists) 字典
  • Hand-crafted rules 手工製作的規則(e.g., to check whether the word following an EOS delimiter starts with an uppercase character 檢查EOS界定符之後的單詞是否從大寫字符開始)
  • Statistical and ML approaches
  • Hybrid approaches 混合方法

Example of useful rules or Features

First character after potential EOS char 潛在EOS Char之後的第一個字符
● Should be uppercase? Problematic for some languages, e.g. German
● Permissible chars after potential EOS, e.g. lowercase characters?
Abbreviations 縮寫
● titles not likely to occur at EOS (e.g., Dr. Jones)
● company indicators could occur at EOS (e.g., MySocialMedia Inc.)

OpenNLP

The OpenNLP Sentence Detector cannot identify sentence boundaries based on the contents of the sentence 無法根據內容識別句子邊界

OpenNLP 開發文檔

輸出的是一個個string 每個string都是一個分解出來的句子

spaCy

for pdf and word docs

spaCy 開發文檔

Tokenisation 象征化

Why need Tokenisation

  • 機器學習模型通常使用「單詞」作為特徵,例如詞頻統計、情感分析等。
  • 英文單詞之間有空格,中文沒有,需要不同的處理方法。

Break sentence into tokens

3 main classes of tokens often considered

  • Morphosyntactic word
  • Punctuation mark or special symbol
  • A number
  • Endings of contractions, e.g., “'re” in “we’re”
  • Compounds and multi-words (e.g., daughter-in-law)

Challenges:

  • Character encoding
    • ASCII only?
    • Unicode (UTF-8)
  • ASCII-fication or romanisation of texts
    • Transliterations
  • Results from OCR may be poor
    • Pre-processing to detect/correct errors 預處理
    • OCR errors may appear as correct text (but not intended text)

[!attention] Challenging

  • Hyphenation
    • Manchester-based
    • Sister-in-law
  • Telephone numbers: many different Formats
    • with whitespace, dots
    • slashes, hyphens, parentheses, plus signs

[!example]+

  • Dates: 04 January 2018; 04-01-2018, Jan 4, 2018
  • Decimals: 0.05; 3.4; .6
  • Monetary values: a £5-a-dish dinner

Split or not to split

  • Sentence segmentation (split)
  • Tokenisation (split)
  • Named entity recognition (combine)
    In other words: tokenisation is knowing when to split (not when to combine)

Annotation Formats

Annotation(標註) 是在文本中為每個 token 添加額外的信息,例如詞性標註Part-of-Speech Tagging, POS Tagging)、命名實體識別Named Entity Recognition, NER)等。

Understanding documents

Documents rarely have a simple structure 很少有簡單結構
Documents are meant to be human-readable

[!example]

  • news article
  • research article

Annotations:

Enabling machine-readablility

在这里插入图片描述

在这里插入图片描述
如圖展示的 他從單純的文字變成機器可讀的樣式

Types of annotation Formats

Boundary notation 邊界符號
Inline markup language elements 內聯標記語言元素
Stand-off

  • delimiter-separated values (DSV)
  • JSON

Part-od-Speech Tagging (POS Tagging) 詞性標註

給每個單詞分配詞性標籤

[!example]

import nltk 
nltk.download('averaged_perceptron_tagger') 
sentence = "She runs fast." 
tokens = word_tokenize(sentence) 
pos_tags = nltk.pos_tag(tokens) 
print(pos_tags) 
# [('She', 'PRP'), ('runs', 'VBZ'), ('fast', 'RB')]

Named Entity Recpgnition (NER) 命名實體識別

NER 用來識別文本中的人名、地名、組織名等專有名詞

句子:
“Apple is looking at buying U.K. startup for $1 billion.”

NER 標註結果:

  1. “Apple” → ORG(組織)
  2. “U.K.” → GPE(地名)
  3. “$1 billion” → MONEY(貨幣)
import spacy 
nlp = spacy.load("en_core_web_sm") 
sentence = "Apple is looking at buying U.K. startup for $1 billion." 
doc = nlp(sentence) for ent in doc.ents: print(ent.text, ent.label_) 
# Apple ORG 
# U.K. GPE# $1 billion MONEY

Boundary Notation

Done at the level of individual tokens 在單個token完成
How do we encode units of interest spanning several tokens
BIO: B=Begin I=Inside O=Outside

[!example]
在这里插入图片描述

  • Strengths
    • simple
  • limitations
    • cannot handle hierarchical or structured annotations e.g., nested entities(NES) 嵌套實體, relations events

[!example] Nested entities

在这里插入图片描述

展示了Named Entity Recognition (NER) 命名實體識別的結果

  • 是一種NLP技術,用來識別文本中的關鍵實體,比如地名 (GPE)組織 (Org), 人物 (Person)事件 (Conflict_Attack)
  • GPE:
    • 國家或地區名稱
  • Org:
    • 機構或組織的名稱
  • Person:
    • 具體人名
  • Contact_Meet:
    • 這類標籤標識涉及會議或高級別會議
  • Conflict_Attack(衝突/攻擊, Conflict_Attack
    • 標識與戰爭或攻擊有關的事件
  • 關係標註(箭頭)
    • 表示某人參與了一場活動
    • Target (目標)
    • 標識某個實體是某個行動的目標

Inline markup language elements

By addition of markup tags within text

  • HTML
  • XML

[!example]
在这里插入图片描述

Strengths:

  • can handle annotations which are hierarchical (e.g., nested NEs, trees) and structured (e.g., events) 可以處理分層的注釋
    Limitations:
  • requires substantial processing with standard XML parsers 對標準XML處理器進行大量處理
  • impossible to encode overlapping/intersecting annotations, e.g., second Iraqi city of Basra 無法編碼重疊/相交注釋

Stand-off Annotations (JSON格式)

將標註信息與原始文本分離的標註方式,而不是將標註直接嵌入到文本內部。

為什麼使用 Stand-off Annotation?

  1. 避免污染原始數據:原始文本保持不變,標註信息存儲在外部文件或數據結構中。
  2. 允許多層次標註:可以為相同文本提供多種標註(如詞性、語法結構、命名實體等),並獨立管理它們。
  3. 便於版本控制:標註數據和原始文本分開存儲,有助於管理不同版本的標註信息。
  4. 支持長文本處理:對於超大文本,標註信息存儲在索引數據結構中,提高效率。

[!example]+

UK and US discuss the role of UN.

stand-off 標註文件

{"text": "UK and US discuss the role of UN.","annotations": [{"id": "T1","type": "GPE","start": 0,"end": 2,"text": "UK"},{"id": "T2","type": "GPE","start": 7,"end": 9,"text": "US"},{"id": "T3","type": "ORG","start": 27,"end": 29,"text": "UN"}]
}

annotations are stored separately
requires a way to link between annotations and text
links annotations to text using indexing based on character offsets (computed over raw
text)

  • strength:
    • original raw text is left untouched 原始文本未觸及
    • can handle structured and overlapping annotations 可以處理結構化和重疊的注釋
  • limitations:
    • not readily human-readable

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/70040.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Linux中线程创建,线程退出,线程接合

线程的简单了解 之前我们了解过 task_struct 是用于描述进程的核心数据结构。它包含了一个进程的所有重要信息,并且在进程的生命周期内保持更新。我们想要获取进程相关信息往往从这里得到。 在Linux中,线程的实现方式与进程类似,每个线程都…

HarmonyOS:使用List实现分组列表(包含粘性标题)

一、支持分组列表 在列表中支持数据的分组展示,可以使列表显示结构清晰,查找方便,从而提高使用效率。分组列表在实际应用中十分常见,如下图所示联系人列表。 联系人分组列表 在List组件中使用ListItemGroup对项目进行分组&#…

django上传文件

1、settings.py配置 # 静态文件配置 STATIC_URL /static/ STATICFILES_DIRS [BASE_DIR /static, ]上传文件 # 定义一个视图函数,该函数接收一个 request 参数 from django.shortcuts import render # 必备引入 import json from django.views.decorators.http i…

【前端知识】浏览器兼容方案polyfill

浏览器兼容方案polyfill 什么是 Polyfill?Polyfill 的作用Polyfill 的工作原理1. **特性检测**2. **加载 Polyfill**3. **模拟实现** Polyfill 的常见场景Polyfill 的使用方式Polyfill 的优缺点优点缺点 常见的 Polyfill 库总结 什么是 Polyfill? Polyf…

C#学习之DateTime 类

目录 一、DateTime 类的常用方法和属性的汇总表格 二、常用方法程序示例 1. 获取当前本地时间 2. 获取当前 UTC 时间 3. 格式化日期和时间 4. 获取特定部分的时间 5. 获取时间戳 6. 获取时区信息 三、总结 一、DateTime 类的常用方法和属性的汇总表格 在 C# 中&#x…

dedecms 开放重定向漏洞(附脚本)(CVE-2024-57241)

免责申明: 本文所描述的漏洞及其复现步骤仅供网络安全研究与教育目的使用。任何人不得将本文提供的信息用于非法目的或未经授权的系统测试。作者不对任何由于使用本文信息而导致的直接或间接损害承担责任。如涉及侵权,请及时与我们联系,我们将尽快处理并删除相关内容。 0x0…

如何选择合适的超参数来训练Bert和TextCNN模型?

选择合适的超参数来训练Bert和TextCNN模型是一个复杂但关键的过程,它会显著影响模型的性能。以下是一些常见的超参数以及选择它们的方法: 1. 与数据处理相关的超参数 最大序列长度(max_length) 含义:指输入到Bert模…

AWS 前端自动化部署流程指南

本文详细介绍从前端代码开发到 AWS 自动化部署的完整流程。 一、流程概览 1.1 部署流程图 #mermaid-svg-nYg7k6L5IKVBjDtr {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-nYg7k6L5IKVBjDtr .error-icon{fill:#552…

Office word打开加载比较慢处理方法

1.添加safe参数 ,找到word启动项,右击word,选择属性 , 添加/safe , 应用并确定 2.取消加载项,点击文件,点击选项 ,点击加载项,点击转到,取消所有勾选,确定。

大数据SQL调优专题——Spark执行原理

引入 在深入MapReduce中有提到,MapReduce虽然通过“分而治之”的思想,解决了海量数据的计算处理问题,但性能还是不太理想,这体现在两个方面: 每个任务都有比较大的overhead,都需要预先把程序复制到各个 w…

MYSQL下载安装及使用

MYSQL官网下载地址:https://downloads.mysql.com/archives/community/ 也可以直接在服务器执行指令下载,但是下载速度比较慢。还是自己下载好拷贝过来比较快。 wget https://dev.mysql.com/get/Downloads/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz 1…

CentOS 7.8 安装MongoDB 7 副本集(Replica Set)

文章目录 1 环境假设步骤1:在两台服务器上安装MongoDB步骤2:配置副本集步骤3:初始化副本集步骤4:验证副本集配置步骤5:设置安全性(可选)扩展配置示例:最佳实践:仲裁节点步…

AJAX 与 ASP 的深入探讨

AJAX 与 ASP 的深入探讨 引言 随着互联网技术的飞速发展,Web应用程序的交互性和性能要求越来越高。AJAX(Asynchronous JavaScript and XML)和ASP(Active Server Pages)作为两种重要的Web开发技术,在提高Web应用程序性能和用户体验方面发挥着重要作用。本文将深入探讨AJ…

内网下,Ubuntu (24.10) 离线安装docker最新版教程

一般在数据比较敏感的情况下,是无法使用网络的,而对于Ubuntu系统来说,怎么离线安装docker呢? 下面我给大家来讲一下: 采用二进制安装: 1.下载docker离线包 官网下载: Index of linux/static…

Copilot Next Edit Suggestions(预览版)

作者:Brigit Murtaugh,Burke Holland 排版:Alan Wang 我们很高兴向你介绍在本次 Visual Studio Code 发布中,关于 GitHub Copilot 的三个预览功能: Next Edit Suggestions(NES)Copilot Edits 的…

高性能内存对象缓存Memcached详细实验操作

目录 前提准备: cache1,2: 客户端cache-api(一定得是LAMP环境) memcache实现主主复制以及高可用(基于以上完成) cache1,2: memcachekeepalived(基于以上完成) cache1,2: 前提准备: 1. 准备三台cent…

全单模矩阵及其在分支定价算法中的应用

全单模矩阵及其在分支定价算法中的应用 目录 全单模矩阵的定义与特性全单模矩阵的判定方法全单模矩阵在优化中的核心价值分支定价算法与矩阵单模性的关系非全单模问题的挑战与系统解决方案总结与工程实践建议 1. 全单模矩阵的定义与特性 关键定义 单模矩阵(Unimo…

Spring AI发布!让Java紧跟AI赛道!

1. 序言 在当今技术发展的背景下,人工智能(AI)已经成为各行各业中不可忽视的重要技术。无论是在互联网公司,还是传统行业,AI技术的应用都在大幅提升效率、降低成本、推动创新。从智能客服到个性化推荐,从语…

【kafka系列】Kafka如何保证消息不丢失?

目录 1. 生产者端:确保消息成功发送到Broker 核心机制: 关键步骤: 2. Broker端:持久化与副本同步 核心机制: 关键源码逻辑: 3. 消费者端:可靠消费与Offset提交 核心机制: 关…

利用二分法+布尔盲注、时间盲注进行sql注入

一、布尔盲注&#xff1a; import requestsdef binary_search_character(url, query, index, low32, high127):while low < high:mid (low high 1) // 2payload f"1 AND ASCII(SUBSTRING(({query}),{index},1)) > {mid} -- "res {"id": payloa…