C# Sdcb.PaddleInference 中文分词、词性标注

C# Sdcb.PaddleInference 中文分词、词性标注

目录

效果

项目

代码

下载

参考


效果

项目

代码

using Sdcb.PaddleNLP.Lac;

using System;

using System.Collections.Generic;

using System.Data;

using System.Linq;

using System.Windows.Forms;

namespace C__Sdcb.PaddleInference_中文分词_词性标注

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

ChineseSegmenter segmenter;

private void button1_Click(object sender, EventArgs e)

{

string input = "我是中国人,我爱我的祖国。";

textBox1.Text = input;

string[] result = segmenter.Segment(input);

textBox2.Text = string.Join(",", result);

}

private void Form1_Load(object sender, EventArgs e)

{

segmenter = new ChineseSegmenter();

}

private void button2_Click(object sender, EventArgs e)

{

string input = "我爱北京天安门";

textBox1.Text = input;

textBox2.Text = "";

WordAndTag[] result = segmenter.Tagging(input);

string labels = string.Join(",", result.Select(x => x.Label));

string words = string.Join(",", result.Select(x => x.Word));

string tags = string.Join(",", result.Select(x => x.Tag));

textBox2.Text += "words:" + words + "\r\n";

textBox2.Text += "labels:" + labels + "\r\n";

textBox2.Text += "tags" + tags + "\r\n";

}

private void button3_Click(object sender, EventArgs e)

{

string input = "我爱北京天安门";

textBox1.Text = input;

textBox2.Text = "";

Dictionary<string, WordTag?> customizedWords = new Dictionary<string, WordTag?>();

customizedWords.Add("北京天安门", WordTag.LocationName);

LacOptions lacOptions = new LacOptions(customizedWords);

ChineseSegmenter segmenter_custom = new ChineseSegmenter(lacOptions);

WordAndTag[] result = segmenter_custom.Tagging(input);

string labels = string.Join(",", result.Select(x => x.Label));

string words = string.Join(",", result.Select(x => x.Word));

string tags = string.Join(",", result.Select(x => x.Tag));

textBox2.Text += "words:" + words + "\r\n";

textBox2.Text += "labels:" + labels + "\r\n";

textBox2.Text += "tags" + tags + "\r\n";

}

}

}

复制代码
using Sdcb.PaddleNLP.Lac;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows.Forms;

namespace C__Sdcb.PaddleInference_中文分词_词性标注
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        ChineseSegmenter segmenter;

        private void button1_Click(object sender, EventArgs e)
        {
            string input = "我是中国人,我爱我的祖国。";
            textBox1.Text = input;
            string[] result = segmenter.Segment(input);
            textBox2.Text = string.Join(",", result);

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            segmenter = new ChineseSegmenter();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string input = "我爱北京天安门";
            textBox1.Text = input;
            textBox2.Text = "";
            WordAndTag[] result = segmenter.Tagging(input);
            string labels = string.Join(",", result.Select(x => x.Label));
            string words = string.Join(",", result.Select(x => x.Word));
            string tags = string.Join(",", result.Select(x => x.Tag));

            textBox2.Text += "words:" + words + "\r\n";
            textBox2.Text += "labels:" + labels + "\r\n";
            textBox2.Text += "tags" + tags + "\r\n";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string input = "我爱北京天安门";
            textBox1.Text = input;
            textBox2.Text = "";

            Dictionary<string, WordTag?> customizedWords = new Dictionary<string, WordTag?>();
            customizedWords.Add("北京天安门", WordTag.LocationName);

            LacOptions lacOptions = new LacOptions(customizedWords);

            ChineseSegmenter segmenter_custom = new ChineseSegmenter(lacOptions);

            WordAndTag[] result = segmenter_custom.Tagging(input);
            string labels = string.Join(",", result.Select(x => x.Label));
            string words = string.Join(",", result.Select(x => x.Word));
            string tags = string.Join(",", result.Select(x => x.Tag));

            textBox2.Text += "words:" + words + "\r\n";
            textBox2.Text += "labels:" + labels + "\r\n";
            textBox2.Text += "tags" + tags + "\r\n";
        }
    }
}

下载

源码下载

参考

https://github.com/sdcb/PaddleSharp/blob/master/docs/paddlenlp-lac.md

相关推荐
薛定谔的猫19826 小时前
二十一、基于 Hugging Face Transformers 实现中文情感分析情感分析
人工智能·自然语言处理·大模型 训练 调优
2501_9333295510 小时前
品牌公关AI化实践:Infoseek舆情系统技术架构解析
人工智能·自然语言处理
余俊晖11 小时前
Qwen3-VL-0.6B?Reyes轻量化折腾:一个从0到1开始训练的0.6B参数量的多模态大模型
人工智能·自然语言处理·多模态
猿小羽12 小时前
RAG 入门与实践指南
自然语言处理·知识库·向量检索·rag·ai实战·检索增强生成
玄同76513 小时前
Llama.cpp 全实战指南:跨平台部署本地大模型的零门槛方案
人工智能·语言模型·自然语言处理·langchain·交互·llama·ollama
玄同76513 小时前
LangChain v1.0+ Prompt 模板完全指南:构建精准可控的大模型交互
人工智能·语言模型·自然语言处理·langchain·nlp·交互·知识图谱
菜青虫嘟嘟15 小时前
Expert Iteration:一种无需人工标注即可显著提升大语言模型推理能力的简单方法核心
人工智能·语言模型·自然语言处理
Loo国昌16 小时前
【垂类模型数据工程】第四阶段:高性能 Embedding 实战:从双编码器架构到 InfoNCE 损失函数详解
人工智能·后端·深度学习·自然语言处理·架构·transformer·embedding
MaoziShan16 小时前
[ICLR 2026] 一文读懂 AutoGEO:生成式搜索引擎优化(GEO)的自动化解决方案
人工智能·python·搜索引擎·语言模型·自然语言处理·内容运营·生成式搜索引擎
渡我白衣20 小时前
【MySQL基础】(2):数据库基础概念
数据库·人工智能·深度学习·神经网络·mysql·机器学习·自然语言处理