Code Monkey home page Code Monkey logo

deepnlp's Introduction

基于 pytorchtransformers 框架实现 NLP 各类任务的 SOTA


文本分类

1. 将训练数据转换为如下的 json 格式

训练数据示例
{
  "text": "以色列大规模空袭开始!伊朗多个军事目标遭遇打击,誓言对等反击",
  "label": "news_military"
}

训练数据包含两个文件train.jsondev.json

2. 通过运行 bash 命令进行模型微调

支持的模型

3. 模型预测

>>> from torchblocks.tasks.tc import TextClassificationPipeline

>>> pipline = TextClassificationPipeline("my_bert_model_path", model_name="fc", model_type="bert")
>>> text = "以色列大规模空袭开始!伊朗多个军事目标遭遇打击,誓言对等反击"
>>> print(pipline(text))

命名实体识别

1. 将训练数据转换为如下的 json 格式

训练数据示例
{
  "text": "结果上周六他们主场0:3惨败给了中游球队瓦拉多利德,近7个多月以来西甲首次输球。", 
  "entities": [
    {
      "id": 0, 
      "entity": "瓦拉多利德", 
      "start_offset": 20, 
      "end_offset": 24, 
      "label": "organization"
    }, 
    {
      "id": 1, 
      "entity": "西甲", 
      "start_offset": 33, 
      "end_offset": 34, 
      "label": "organization"
    }
  ]
}

训练数据包含两个文件train.jsondev.json

2. 通过运行 bash 命令进行模型微调

支持的模型

3. 模型预测

>>> from pprint import pprint
>>> from torchblocks.tasks.ner import NERPipeline

>>> pipline = NERPipeline("my_bert_model_path", model_name="crf", model_type="bert")
>>> text = "结果上周六他们主场0:3惨败给了中游球队瓦拉多利德,近7个多月以来西甲首次输球。"
>>> pprint(pipline(text))

实体关系抽取

1. 将训练数据转换为如下的 json 格式

训练数据示例
{
  "text": "查尔斯·阿兰基斯(Charles Aránguiz),1989年4月17日出生于智利圣地亚哥,智利职业足球运动员,司职中场,效力于德国足球甲级联赛勒沃库森足球俱乐部", 
  "spo_list": [
    {
      "predicate": "出生地", 
      "object_type": "地点", 
      "subject_type": "人物", 
      "object": "圣地亚哥", 
      "subject": "查尔斯·阿兰基斯"
    }, 
    {
      "predicate": "出生日期", 
      "object_type": "Date", 
      "subject_type": "人物", 
      "object": "1989年4月17日",
      "subject": "查尔斯·阿兰基斯"
    }
  ]
}

训练数据包含两个文件train.jsondev.json

2. 通过运行 bash 命令进行模型微调

支持的模型

3. 模型预测

>>> from pprint import pprint
>>> from torchblocks.tasks.ere import REPipeline

>>> pipline = REPipeline("my_bert_model_path", model_name="gplinker", model_type="bert")
>>> text = "查尔斯·阿兰基斯(Charles Aránguiz),1989年4月17日出生于智利圣地亚哥,智利职业足球运动员,司职中场,效力于德国足球甲级联赛勒沃库森足球俱乐部。"
>>> pprint(pipline(text))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.