Configs2026年7月16日·1 分钟阅读

HanLP — Multi-Language NLP Library for Production

Joint multi-task NLP framework supporting tokenization, POS tagging, NER, parsing, and more across 100+ languages.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
HanLP Overview
直接安装命令
npx -y tokrepo@latest install 4dd02b7f-8135-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

HanLP is a production-ready NLP library that provides joint multi-task learning models for 100+ languages. Originally built for Chinese NLP, it has grown into a multilingual framework with state-of-the-art transformer-based models for tokenization, part-of-speech tagging, named entity recognition, dependency parsing, and semantic role labeling.

What HanLP Does

  • Tokenizes and segments text across Chinese, English, Japanese, and 100+ other languages
  • Performs part-of-speech tagging, lemmatization, and morphological feature extraction
  • Extracts named entities (person, location, organization) and custom entity types
  • Builds dependency parse trees and semantic dependency graphs
  • Runs semantic role labeling and constituency parsing in a single forward pass

Architecture Overview

HanLP v2 uses a multi-task learning architecture where a shared transformer encoder (XLM-R or ELECTRA) feeds into task-specific decoders. This design allows all NLP tasks to share representations, reducing memory and improving accuracy through transfer learning. Models are loaded lazily and cached locally for offline use.

Setup & Configuration

  • Install via pip install hanlp for the full package or hanlp[tf] for TensorFlow backend
  • Download pretrained models on first use; they cache under ~/.hanlp
  • Use hanlp.pretrained to browse available model keys by task and language
  • Configure GPU usage via standard PyTorch or TensorFlow device placement
  • Deploy as a REST service with hanlp.server or integrate via the Java API for JVM projects

Key Features

  • Joint multi-task inference runs all NLP tasks in one forward pass
  • Pretrained models for 100+ languages based on Universal Dependencies
  • Supports both PyTorch and TensorFlow backends
  • RESTful server mode for production microservice deployments
  • Java API available for JVM-based applications

Comparison with Similar Tools

  • spaCy — production-focused single-task pipelines, HanLP offers joint multi-task models
  • Stanza — Stanford research-oriented, HanLP provides broader language coverage
  • NLTK — educational and rule-based, HanLP is transformer-based and faster
  • jieba — Chinese segmentation only, HanLP covers full NLP pipeline

FAQ

Q: Does HanLP support languages other than Chinese? A: Yes. HanLP v2 supports 100+ languages through multilingual transformer models trained on Universal Dependencies treebanks.

Q: Can I fine-tune HanLP models on my own data? A: Yes. HanLP provides training scripts and configuration files for fine-tuning on custom datasets in CoNLL format.

Q: What is the difference between HanLP v1 and v2? A: v1 uses traditional algorithms and a Java API. v2 is transformer-based, Python-first, and supports multi-task learning.

Q: How large are the pretrained models? A: Base models are around 500 MB. Larger models with more tasks can reach 1-2 GB.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产