Natural Language Processing with R: POS Tagging and Named Entity Recognition

Part-of-Speech (POS) tagging is a fundamental NLP task that assigns grammatical categories—such as nouns, verbs, or adjectives—to individual words within a tokenized sequence. In the context of the Chinese language, precise POS tagging is essential for information extraction and stylometric analysis. When using the jiebaR package for R, the underlying models are trained on the Peking University People's Daily corpus, adhering to the ICTPOS 3.0 tag set.

POS Tagging Implementation

The jiebaR package supports tagging either raw strings directly or pre-tokenized character vectors. Below is an example of tagging a raw string:

library(jiebaR)
library(dplyr)
library(tibble)

# Initialize a tagger worker
tag_engine <- worker(type = "tag")

# Input text
text_sample <- "I want to write a book titled R Language Data Processing."

# Perform tagging
tagged_output <- tagging(text_sample, tag_engine)

# Convert the result to a tidy data frame
tidy_tags <- enframe(tagged_output, name = "pos", value = "token")
print(tidy_tags)

If you have already processed the text into tokens, you can use the vector_tag function to apply tags efficiently without re-tokenizing:

# Tokenize first
tokens <- segment("I want to write a book.", worker())

# Apply POS tags to tokens
pos_results <- vector_tag(tokens, tag_engine)

Named Entity Recognition via POS Filtering

By filtering for specific tags (e.g., "n" for nouns), we can extract potantial entities from a text. This approach is useful for identifying the subjects or objects that form the core context of a document. The following example demonstrates how to extract and rank nouns from a provided text corpus:

# Assuming 'full_text' contains a long narrative
# 1. Tag the text
# 2. Extract nouns (pos == 'n')
# 3. Count frequencies to identify key subjects

entity_analysis <- tagging(full_text, tag_engine) %>%
 enframe(name = "pos", value = "token") %>%
 filter(pos == "n") %>%
 count(token, sort = TRUE)

print(head(entity_analysis, 10))

Enhancing Accuracy with Custom Dictionaries

Generic models often struggle with domain-specific terminology. To improve POS accuracy, you should leverage custom user dictionaries. By defining your own terms and explicitly specifying their grammatical types in a dictionary file (typically found by inspecting DICTPATH in jiebaR), you can significantly improve the quality of your extractions. Always remember that for professional NLP tasks, the quality and specificity of your dictionary often outweigh the complexity of the underlying algorithm.

Tags: R jiebaR NLP POS-Tagging Text-Mining

Posted on Sat, 12 Sep 2026 16:09:26 +0000 by Tekron-X