Skip to content

Applying custom Huggingface model as an encoder #2057

Answered by jppgks
efima-ai asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @efima-ai, you can use arbitrary HuggingFace models using the auto_transformer encoder. You can try something like this for your case:

import pandas as pd
import yaml

from ludwig.api import LudwigModel

config = """
input_features:
    - name: text
      type: text
      encoder: auto_transformer
      pretrained_model_name_or_path: 'TurkuNLP/bert-base-finnish-cased-v1'
output_features:
    - name: category
      type: category
trainer:
    epochs: 1
"""
model = LudwigModel(yaml.load(config), backend="local")

df = pd.DataFrame(
    {
        "text": ["Suomessa vaihtuu kesän aikana sekä pääministeri että valtiovarain"],
        "category": ["Suomi"],
    }
)
model.train(df)
model.predict

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@efima-ai
Comment options

Answer selected by jppgks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants