update
Browse files- README.md +20 -1
- pipeline.py +30 -0
- requirements.txt +1 -0
README.md
CHANGED
@@ -1,3 +1,22 @@
|
|
1 |
---
|
2 |
-
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
tags:
|
3 |
+
- text-classification
|
4 |
+
library_name: generic
|
5 |
---
|
6 |
+
|
7 |
+
# Text Classification repository template
|
8 |
+
|
9 |
+
This is a template repository for Text Classification to support generic inference with Hugging Face Hub generic Inference API. There are two required steps:
|
10 |
+
|
11 |
+
1. Specify the requirements by defining a `requirements.txt` file.
|
12 |
+
2. Implement the `pipeline.py` `__init__` and `__call__` methods. These methods are called by the Inference API. The `__init__` method should load the model and preload all the elements needed for inference (model, processors, tokenizers, etc.). This is only called once. The `__call__` method performs the actual inference. Make sure to follow the same input/output specifications defined in the template for the pipeline to work.
|
13 |
+
|
14 |
+
## How to start
|
15 |
+
First create a repo in https://hf.co/new.
|
16 |
+
Then clone this template and push it to your repo.
|
17 |
+
```
|
18 |
+
git clone https://huggingface.co/templates/text-classification
|
19 |
+
cd text-classification
|
20 |
+
git remote set-url origin https://huggingface.co/$YOUR_USER/$YOUR_REPO_NAME
|
21 |
+
git push --force
|
22 |
+
```
|
pipeline.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Dict, List
|
2 |
+
import numpy as np
|
3 |
+
import tensorflow as tf
|
4 |
+
|
5 |
+
class PreTrainedPipeline():
|
6 |
+
def __init__(self, path=""):
|
7 |
+
# IMPLEMENT_THIS
|
8 |
+
# Preload all the elements you are going to need at inference.
|
9 |
+
# For instance your model, processors, tokenizer that might be needed.
|
10 |
+
# This function is only called once, so do all the heavy processing I/O here"""
|
11 |
+
# raise NotImplementedError(
|
12 |
+
# "Please implement PreTrainedPipeline __init__ function"
|
13 |
+
# )
|
14 |
+
pass
|
15 |
+
|
16 |
+
def __call__(self, inputs: str) -> List[List[Dict[str, float]]]:
|
17 |
+
"""
|
18 |
+
Args:
|
19 |
+
inputs (:obj:`str`):
|
20 |
+
a string containing some text
|
21 |
+
Return:
|
22 |
+
A :obj:`list`:. The object returned should be a list of one list like [[{"label": 0.9939950108528137}]] containing :
|
23 |
+
- "label": A string representing what the label/class is. There can be multiple labels.
|
24 |
+
- "score": A score between 0 and 1 describing how confident the model is for this label/class.
|
25 |
+
"""
|
26 |
+
# IMPLEMENT_THIS
|
27 |
+
# raise NotImplementedError(
|
28 |
+
# "Please implement PreTrainedPipeline __call__ function"
|
29 |
+
# )
|
30 |
+
return [[{"label": inputs, "score":0.2}]]
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
tensorflow
|