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

相关推荐
阿部多瑞 ABU8 小时前
# 从底层架构到应用实践:为何部分大模型在越狱攻击下失守?
gpt·安全·ai·自然语言处理
vlln12 小时前
【论文解读】MemGPT: 迈向为操作系统的LLM
人工智能·深度学习·自然语言处理·transformer
胡耀超16 小时前
大语言模型提示词(LLM Prompt)工程系统性学习指南:从理论基础到实战应用的完整体系
人工智能·python·语言模型·自然语言处理·llm·prompt·提示词
要努力啊啊啊16 小时前
强化学习基础概念图文版笔记
论文阅读·人工智能·笔记·深度学习·语言模型·自然语言处理
程序员老周66617 小时前
4.大语言模型预备数学知识
人工智能·神经网络·线性代数·自然语言处理·大语言模型·概率论·数学基础
蓦然回首却已人去楼空1 天前
Build a Large Language Model (From Scratch) 序章
人工智能·语言模型·自然语言处理
CM莫问1 天前
<论文>(微软)WINA:用于加速大语言模型推理的权重感知神经元激活
人工智能·算法·语言模型·自然语言处理·大模型·推理加速
MYH5161 天前
在NLP文本处理中,将字符映射到阿拉伯数字(构建词汇表vocab)的核心目的和意义
人工智能·深度学习·自然语言处理
要努力啊啊啊1 天前
KV Cache:大语言模型推理加速的核心机制详解
人工智能·语言模型·自然语言处理
Jamence1 天前
多模态大语言模型arxiv论文略读(108)
论文阅读·人工智能·语言模型·自然语言处理·论文笔记