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.pswp.cn/web/70040.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/70040.shtml
英文地址,請注明出處:http://en.pswp.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…