Skip to contents

Task pipeline: preprocess -> model -> postprocess (Geron Ch 14, morie.fn hmhfpi)

Usage

morie_geron_hf_pipelines(task, inputs, model, labels = NULL, top_k = 1)

Arguments

task

One of text-classification, sentiment-analysis, feature-extraction, text-generation.

inputs

List of inputs.

model

function(inputs) -> raw output.

labels

Optional label names.

top_k

Ranked labels per input.

Value

List with predictions, scores, raw, task, estimate, n, method.

Examples

logits <- function(xs) matrix(c(2, 0, 0, 3), nrow = 2, byrow = TRUE)
morie_geron_hf_pipelines("sentiment-analysis", list("good", "bad"),
    logits, labels = c("POSITIVE", "NEGATIVE"))
#> $predictions
#> $predictions[[1]]
#> $predictions[[1]]$label
#> [1] "POSITIVE"
#> 
#> $predictions[[1]]$score
#> [1] 0.8807971
#> 
#> 
#> $predictions[[2]]
#> $predictions[[2]]$label
#> [1] "NEGATIVE"
#> 
#> $predictions[[2]]$score
#> [1] 0.9525741
#> 
#> 
#> 
#> $scores
#>            [,1]      [,2]
#> [1,] 0.88079708 0.1192029
#> [2,] 0.04742587 0.9525741
#> 
#> $raw
#>      [,1] [,2]
#> [1,]    2    0
#> [2,]    0    3
#> 
#> $task
#> [1] "sentiment-analysis"
#> 
#> $estimate
#> [1] 0.9166856
#> 
#> $n
#> [1] 2
#> 
#> $method
#> [1] "Task pipeline (preprocess -> model -> postprocess)"
#>