Class: Transformers::FeatureExtractionPipeline
- Inherits:
-
Pipeline
- Object
- Pipeline
- Transformers::FeatureExtractionPipeline
show all
- Defined in:
- lib/transformers/pipelines/feature_extraction.rb
Instance Method Summary
collapse
Methods inherited from Pipeline
#_ensure_tensor_on_device, #call, #check_model_type, #get_iterator, #initialize, #torch_dtype
Instance Method Details
#_forward(model_inputs) ⇒ Object
31
32
33
34
|
# File 'lib/transformers/pipelines/feature_extraction.rb', line 31
def _forward(model_inputs)
model_outputs = @model.(**model_inputs)
model_outputs
end
|
#_sanitize_parameters(truncation: nil, tokenize_kwargs: nil, return_tensors: nil, **kwargs) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/transformers/pipelines/feature_extraction.rb', line 3
def _sanitize_parameters(truncation: nil, tokenize_kwargs: nil, return_tensors: nil, **kwargs)
if tokenize_kwargs.nil?
tokenize_kwargs = {}
end
if !truncation.nil?
if tokenize_kwargs.include?(:truncation)
raise ArgumentError,
"truncation parameter defined twice (given as keyword argument as well as in tokenize_kwargs)"
end
tokenize_kwargs[:truncation] = truncation
end
preprocess_params = tokenize_kwargs
postprocess_params = {}
if !return_tensors.nil?
postprocess_params[:return_tensors] = return_tensors
end
[preprocess_params, {}, postprocess_params]
end
|
#postprocess(model_outputs, return_tensors: false) ⇒ Object
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/transformers/pipelines/feature_extraction.rb', line 36
def postprocess(model_outputs, return_tensors: false)
if return_tensors
model_outputs[0]
elsif @framework == "pt"
model_outputs[0].to_a
elsif @framework == "tf"
raise Todo
end
end
|
#preprocess(inputs, **tokenize_kwargs) ⇒ Object
26
27
28
29
|
# File 'lib/transformers/pipelines/feature_extraction.rb', line 26
def preprocess(inputs, **tokenize_kwargs)
model_inputs = @tokenizer.(inputs, return_tensors: @framework, **tokenize_kwargs)
model_inputs
end
|