forked from PaddlePaddle/Paddle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the word segmentation task in the Taskflow (PaddlePaddle#1123)
* Add the word segmentation task in the Taskflow * format the example in the taskflow * remove the limit for seq length for the segment * Add the poetry_generation and question answering tasks * change the text2knowledge to ner task * update some code for the taskflow * add the pos tagging for the taskflow * Update the doc for the taskflow tasks * update the pos tagging doc Co-authored-by: Zeyu Chen <[email protected]>
- Loading branch information
Showing
11 changed files
with
464 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# coding:utf-8 | ||
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License" | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import glob | ||
import json | ||
import math | ||
import os | ||
import copy | ||
import itertools | ||
|
||
import numpy as np | ||
from .utils import download_file | ||
from .text_generation import TextGenerationTask | ||
from .task import Task | ||
|
||
usage = r""" | ||
from paddlenlp import Taskflow | ||
poetry = Taskflow("poetry_generation") | ||
poetry("林密不见人") | ||
''' | ||
[{'text': '林密不见人', 'answer': ',但闻人语响。'}] | ||
''' | ||
poetry(["林密不见人", "举头邀明月"]) | ||
''' | ||
[{'text': '林密不见人', 'answer': ',但闻人语响。'}, {'text': '举头邀明月', 'answer': ',低头思故乡。'}] | ||
''' | ||
""" | ||
|
||
URLS = { | ||
"gpt-cpm-large-cn": [ | ||
"https://paddlenlp.bj.bcebos.com/taskflow/text_generation/gpt-cpm/gpt-cpm-large-cn_params.tar", | ||
"5aad6f81053cfdbba4797f044fcf66d1" | ||
], | ||
} | ||
|
||
|
||
class PoetryGenerationTask(TextGenerationTask): | ||
""" | ||
The text generation model to predict the question or chinese poetry. | ||
Args: | ||
task(string): The name of task. | ||
model(string): The model name in the task. | ||
kwargs (dict, optional): Additional keyword arguments passed along to the specific task. | ||
""" | ||
|
||
def __init__(self, task, model, **kwargs): | ||
super().__init__(task=task, model=model, **kwargs) | ||
if self._static_mode: | ||
download_file( | ||
self._task_path, "static" + os.path.sep + "inference.pdiparams", | ||
URLS[self.model][0], URLS[self.model][1], "poetry_generation") | ||
self._get_inference_model() | ||
else: | ||
self._construct_model(model) | ||
self._construct_tokenizer(model) | ||
self.kwargs['generation_task'] = 'poetry_generation' |
Oops, something went wrong.