(링크MS) Statistical text analysis in natural language processing

 


https://learn.microsoft.com/en-us/training/modules/introduction-language/3-statistical-techniques?pivots=text



텍스트 코퍼스를 구성 토큰으로 분해하고 이를 분석용으로 준비한 경우, 텍스트에서 의미를 추론할 수 있는 일반적인 통계 분석 기법이 몇 가지 있습니다.

주파수 분석

아마도 문서에서 논의된 주제를 파악하는 가장 명백한 방법은 각 정규화된 토큰이 나타나는 횟수를 단순히 세는 것입니다. 가정은 문서에서 더 자주 사용되는 용어가 논의된 주제나 주제를 식별하는 데 도움이 될 수 있다는 것입니다. 간단히 말하면, 주어진 문서에서 가장 많이 사용되는 단어들을 파악할 수 있다면, 그 문서가 무엇에 관한 것인지 잘 파악할 수 있습니다.

예를 들어, 다음 텍스트를 고려하십시오:

AI in modern business delivers transformative benefits by enhancing efficiency, decision-making, and customer experiences. Businesses can leverage AI to automate repetitive tasks, freeing employees to focus on strategic work, while predictive analytics and machine learning models enable data-driven decisions that improve accuracy and speed. AI-powered tools like Copilot streamline workflows across marketing, finance, and operations, reducing costs and boosting productivity. Additionally, intelligent applications personalize customer interactions, driving engagement and loyalty. By embedding AI into core processes, businesses benefit from the ability to innovate faster, adapt to market changes, and maintain a competitive edge in an increasingly digital economy.

텍스트에 토큰화, 정규화 및 레마타화를 적용한 후, 각 항의 빈도를 계산하고 표로 정리하여 다음과 같은 부분 결과를 도출합니다:

용어주파수
ai4
business3
benefit2
customer2
decision2
market2
ability1
accuracy1
......

이러한 결과로부터 가장 자주 등장하는 용어는 해당 텍스트가 AI와 그 비즈니스적 이점을 논의하고 있음을 나타냅니다.

용어 빈도 - 역문서 빈도 (TF-IDF)

각 토큰의 발생 횟수를 계산하는 간단한 빈도 분석은 단일 문서를 분석하는 효과적인 방법이 될 수 있지만, 동일한 코퍼스 내 여러 문서를 구분해야 할 경우 각 개별 문서에서 가장 관련성이 높은 토큰을 판단할 수 있는 방법이 필요합니다.

예를 들어, 다음 두 텍스트 샘플을 고려하십시오:

샘플 A:

Microsoft Copilot Studio enables declarative AI agent creation using natural language, prompts, and templates. With this declarative approach, an AI agent is configured rather than programmed: makers define intents, actions, and data connections, then publish the agent to channels. Microsoft Copilot Studio simplifies agent orchestration, governance, and lifecycles so an AI agent can be iterated quickly. Using Microsoft Copilot Studio helps modern businesses deploy Microsoft AI agent solutions fast.

샘플 B:

Microsoft Foundry enables code‑based AI agent development with SDKs and APIs. Developers write code to implement agent conversations, tool calling, state management, and custom pipelines. In Microsoft Foundry, engineers can use Python or Microsoft C#, integrate Microsoft AI services, and manage CI/CD to deploy the AI agent. This code-first development model supports extensibility and performance while building Microsoft Foundry AI agent applications.

이 샘플에서 가장 빈번하게 사용되는 상위 세 용어는 다음 표에 표시되어 있습니다.

샘플 A:

용어주파수
agent6
ai4
microsoft4

샘플 B:

용어주파수
microsoft5
agent4
ai4

As you can see from the results, the most common words in both samples are the same ("agent""Microsoft", and "AI"). This tells us that both documents cover a similar overall theme, but doesn't help us discriminate between the individual documents. Examining the counts of less frequently used terms might help, but you can easily imagine an analysis of a corpus based on Microsoft's AI documentation, which would result in a large number of terms that are common across all documents; making it hard to determine the specific topics covered in each document.

이 문제를 해결하기 위해, 용어 빈도 - 역문서 빈도(TF-IDF)는 단어나 용어가 한 문서에서 나타나는 빈도와 전체 문서 컬렉션 전반에 걸친 보다 일반적인 빈도를 비교하여 점수를 계산하는 기법입니다. 이 기법을 사용하면 특정 문서에서는 자주 나타나는 단어에 대해 높은 수준의 관련성을 가정하지만, 다른 다양한 문서에서는 비교적 드물게 나타나는 것으로 가정됩니다. 개별 문서에서 용어에 대한 TF‐IDF를 계산하려면 다음의 3단계 절차를 사용할 수 있습니다.

  1. 용어 빈도 계산 (TF): 이는 문서에 단어가 나타나는 횟수를 간단히 의미합니다. 예를 들어, 문서에 "agent"라는 단어가 6번 나타난다면, tf(agent) = 6

  2. Calculate Inverse Document Frequency (IDF): This checks how common or rare a word is across all documents. If a word appears in every document, it’s not special. The formula used to calculate IDF is idf(t) = log(N / df(t))(where N is total number of documents and df(t) is the number of documents that contain the word t)

  3. 두 값을 결합하여 TF‐IDF를 계산합니다: TF와 IDF를 곱하여 점수를 구합니다:tfidf(t, d) = tf(t, d) * log(N / df(t))

A high TF-IDF score indicates that a word appears often in one document but rarely in others. A low score indicates that word is common in many documents. In two samples about AI agents, because "AI""Microsoft", and "agent" appear in both samples (N = 2, df(t) = 2), their IDF is log(2/2) = 0, so they carry no discriminative weight in TF‑IDF. The top three TF-IDF results for the samples are:

샘플 A:

용어TF-IDF
copilot2.0794
studio2.0794
declarative1.3863

샘플 B:

용어TF-IDF
code2.0794
develop2.0794
foundry2.0794

이러한 결과를 통해 샘플 A는 Copilot Studio를 사용한 선언적 에이전트 생성에 관한 것이며, 샘플 B는 Microsoft Foundry를 사용한 코드 기반 에이전트 개발에 관한 것임을 더 명확히 알 수 있습니다.

"Bag-of-words" 머신러닝 기법

Bag-of-words는 텍스트 토큰을 단어 빈도나 발생의 벡터로 표현하고, 문법과 어순을 무시하는 특징 추출 기법에 부여된 이름입니다. 이 표현은 Naive Bayes와 같은 머신러닝 알고리즘의 입력이 되며, Bayes는 단어 빈도에 따라 문서의 가능한 클래스를 예측하기 위해 Bayes 정리를 적용하는 확률적 분류기입니다.

For example, you might use this technique to train a machine learning model that performs email spam filtering. The words "miracle cure""lose weight fast", and `"anti-aging`` may appear more frequently in spam emails about dubious health products than your regular emails, and a trained model might flag messages containing these words as potential spam.

감정 분석을 구현하려면 같은 방법을 사용하여 텍스트를 감정적 톤으로 분류할 수 있습니다. 단어백은 특징을 제공하고, 모델은 해당 특징을 사용하여 확률을 추정하고 “긍정” 또는 “부정”과 같은 감정 라벨을 지정합니다.

텍스트랭크

TextRank은 텍스트를 연결된 노드들의 네트워크로 모델링하는 비지도 그래프 기반 알고리즘입니다. 예를 들어, 문서의 각 문장은 노드로 간주될 수 있으며, 그 사이의 연결(에지)은 포함된 단어들의 유사성을 기준으로 점수가 매겨집니다. TextRank는 문서 내에서 전체 주제를 가장 잘 나타내는 문장의 하위 집합을 식별하여 텍스트를 요약하는 데 일반적으로 사용됩니다.

TextRank 알고리즘은 Google의 PageRank 알고리즘(웹 페이지 간 링크를 기반으로 순위를 매기는)과 동일한 원리를 텍스트에 적용합니다. 핵심 아이디어는 문장이 다른 많은 중요한 문장들과 유사할 때 중요하다는 것입니다. 알고리즘은 다음 단계들을 통해 작동합니다:

  1. 그래프를 작성하십시오: 각 문장은 노드가 되며, 이를 연결하는 가장자리는 유사도에 의해 가중치를 가중치합니다(주로 단어 겹침이나 문장 벡터 간의 코사인 유사성을 사용하여 측정됩니다).

  2. 반복적으로 순위를 계산합니다: 각 노드의 점수는 연결된 노드의 점수를 기반으로 계산됩니다. 공식은 다음과 같습니다: TextRank(Sᵢ) = (1-d) + d * Σ(wⱼᵢ / Σwⱼₖ) * TextRank(Sⱼ)j) * TextRank(Sj) (여기서 d는 감쇠 계수로, 일반적으로 0.85이며, wji는 문장 j에서 문장 i까지의 가장자리의 가중치이며, 그 합은 i에 연결된 모든 문장을 순회합니다).

  3. 상위 순위 문장을 추출합니다: 수렴 후, 가장 높은 점수를 받은 문장을 요약으로 선택합니다.

예를 들어, 클라우드 컴퓨팅에 관한 다음 문서를 고려하십시오:

Cloud computing provides on-demand access to computing resources. Computing resources include servers, storage, and networking. Azure is Microsoft's cloud computing platform. Organizations use cloud platforms to reduce infrastructure costs. Cloud computing enables scalability and flexibility.

이 문서의 요약을 생성하려면, TextRank 프로세스가 이 문서를 문장으로 나누는 것으로 시작합니다:

  1. Cloud computing provides on-demand access to computing resources.
  2. Computing resources include servers, storage, and networking.
  3. Azure is Microsoft's cloud computing platform.
  4. Organizations use cloud platforms to reduce infrastructure costs.
  5. Cloud computing enables scalability and flexibility.

다음으로, 유사도(단어 겹침)를 기반으로 가중치를 가진 문장 사이에 가장자리가 생성됩니다. 이 예에서는 가장자리 가중치가 다음과 같을 수 있습니다:

  • 문장 1 <-> 문장 2: 0.5 (공유 "computing resources"
  • 문장 1 <-> 문장 3: 0.6 (공유 "cloud computing"
  • 문장 1 <-> 문장 4: 0.2 (공유 "cloud"
  • 문장 1 <-> 문장 5: 0.7 (공유 "cloud computing"
  • 문장 2 <-> 문장 3: 0.2 (제한된 겹침)
  • 문장 2 <-> 문장 4: 0.1 (제한된 겹침)
  • 문장 2 <-> 문장 5: 0.1 (공유 "computing"
  • 문장 3 <-> 문장 4: 0.5 (공유 "cloud platforms"
  • 문장 3 <-> 문장 5: 0.4 (공유 "cloud computing"
  • 문장 4 <-> 문장 5: 0.3 (제한된 겹침)

연결된 문장 노드의 다이어그램.

이러한 가중치를 사용하여 TextRank 점수를 반복적으로 계산한 후, 문장 1, 3, 5는 공통된 용어와 개념을 통해 다른 문장과 잘 연결되기 때문에 가장 높은 점수를 받을 수 있습니다. 이 문장들은 간결한 요약을 만들기 위해 선택됩니다:"Cloud computing provides on-demand access to computing resources. Azure is Microsoft's cloud computing platform. Cloud computing enables scalability and flexibility."

 참고

가장 관련성 높은 문장을 선택하여 문서 요약을 생성하는 것은 추출 요약의 한 형태입니다. 이 접근 방식에서는 새로운 텍스트가 생성되지 않으며, 요약은 원본 텍스트의 일부로 구성됩니다. 최근의 의미 모델링 개발은 또한 추상적 요약을 가능하게 하며, 이를 통해 원본 문서의 핵심 주제를 요약하는 새로운 언어가 생성됩니다.

TextRank는 단어 수준에서 키워드 추출에 적용될 수 있으며, 여기서 단어(문장이 아니라)는 노드가 되고, 가장자리는 고정된 창 내에서 동시 발생을 나타냅니다. 가장 높은 순위에 오른 단어들은 문서의 주요 주제를 나타내는 핵심 용어로 추출됩니다.

댓글