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

相关推荐
0x21125 分钟前
[论文阅读]ReAct: Synergizing Reasoning and Acting in Language Models
人工智能·语言模型·自然语言处理
Jamence38 分钟前
多模态大语言模型arxiv论文略读(三十六)
人工智能·语言模型·自然语言处理
www_pp_40 分钟前
# 构建词汇表:自然语言处理中的关键步骤
前端·javascript·自然语言处理·easyui
微学AI1 小时前
融合注意力机制和BiGRU的电力领域发电量预测项目研究,并给出相关代码
人工智能·深度学习·自然语言处理·注意力机制·bigru
小oo呆11 小时前
【自然语言处理与大模型】模型压缩技术之量化
人工智能·自然语言处理
yuanlaile12 小时前
AI大模型自然语言处理能力案例演示
人工智能·ai·自然语言处理
Jamence13 小时前
多模态大语言模型arxiv论文略读(三十九)
人工智能·语言模型·自然语言处理
ai大模型木子13 小时前
嵌入模型(Embedding Models)原理详解:从Word2Vec到BERT的技术演进
人工智能·自然语言处理·bert·embedding·word2vec·ai大模型·大模型资料
鸿蒙布道师16 小时前
OpenAI为何觊觎Chrome?AI时代浏览器争夺战背后的深层逻辑
前端·人工智能·chrome·深度学习·opencv·自然语言处理·chatgpt
生信宝典16 小时前
Nature method: 生物研究中的语言模型入门指南
人工智能·语言模型·自然语言处理