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

相关推荐
九筠15 小时前
【自然语言处理】word2vec
人工智能·自然语言处理·word2vec
Power202466616 小时前
NLP论文速读(MPO)|通过混合偏好优化提高多模态大型语言模型的推理能力
人工智能·深度学习·语言模型·自然语言处理·自动化·nlp
Guofu_Liao18 小时前
大语言模型---ReLU函数的计算过程及其函数介绍
人工智能·语言模型·自然语言处理
冷冻工厂19 小时前
解码语言:命名实体识别(NER)技术
自然语言处理
青松@FasterAI20 小时前
【RAG 项目实战 05】重构:封装代码
人工智能·深度学习·自然语言处理·nlp
阿勉要睡觉20 小时前
自然语言处理(词嵌入和词向量的使用)
自然语言处理
chnyi6_ya20 小时前
论文笔记:Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks
论文阅读·人工智能·自然语言处理
EterNity_TiMe_20 小时前
【论文复现】BERT模型解读与简单任务实现
人工智能·深度学习·语言模型·自然语言处理·性能优化·bert
Guofu_Liao20 小时前
大语言模型---Llama7B和Llama8B的区别;模型参数量;权重文件的不同;嵌入层权重的不同;输入序列长度的不同;应用场景
人工智能·语言模型·自然语言处理·llama
xianghan收藏册1 天前
大模型(LLMs)推理篇
人工智能·深度学习·自然语言处理·chatgpt·transformer