Views / Computed Column based on ml results #1505
-
create table comment(
id uuid primary key,
content text not null
) how would i create a view or a computed column sentiment based on 'text-classification' |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Running models are a slightly more expensive operation, so you likely want to store the data in both cases. You can store data with a Assuming you want this to be fast and efficient, rather than prompting an LLM like Llama-3, you'll need to choose a Then you can have your column be a call to CREATE TABLE comments (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
content TEXT NOT NULL,
sentiment JSONB NOT NULL GENERATED ALWAYS AS (pgml.transform(
task => '{
"task": "text-classification",
"model": "distilbert/distilbert-base-uncased-finetuned-sst-2-english"
}',
inputs => ARRAY[content]
)) STORED
); Insert a comment:
Check out the result: SELECT * FROM comments;
id | content | sentiment
--------------------------------------+---------+------------------------------------------------------
fc9f1792-c116-4d7c-9a96-8ece196f3cac | hi mom | [{"label": "POSITIVE", "score": 0.9992502331733704}] |
Beta Was this translation helpful? Give feedback.
-
One more note: Text classification models are sensitive to the training data and labels they're trained on. There's a long tail of models out there. You can choose whatever you want for dedicated or self hosted deployments, but we don't supply any particular text-classification models in our serverless instance. You'll need to request a specific model there and we can get it loaded for you. |
Beta Was this translation helpful? Give feedback.
Running models are a slightly more expensive operation, so you likely want to store the data in both cases. You can store data with a
CREATE MATERIALIZED VIEW
orGENERATED AS ... STORED
.Assuming you want this to be fast and efficient, rather than prompting an LLM like Llama-3, you'll need to choose a
text-classfication
model. https://huggingface.co/models?pipeline_tag=text-classification&sort=trendingThen you can have your column be a call to
pgml.transform()