Class: Informers::Utils::LogitsProcessorList
- Inherits:
-
Object
- Object
- Informers::Utils::LogitsProcessorList
- Defined in:
- lib/informers/utils/generation.rb
Instance Method Summary collapse
- #call(input_ids, batched_logits) ⇒ Object
- #concat(items) ⇒ Object
-
#initialize ⇒ LogitsProcessorList
constructor
A new instance of LogitsProcessorList.
- #push(item) ⇒ Object
- #to_ary ⇒ Object
Constructor Details
#initialize ⇒ LogitsProcessorList
Returns a new instance of LogitsProcessorList.
159 160 161 162 |
# File 'lib/informers/utils/generation.rb', line 159 def initialize super @processors = [] end |
Instance Method Details
#call(input_ids, batched_logits) ⇒ Object
172 173 174 175 176 177 178 179 180 181 |
# File 'lib/informers/utils/generation.rb', line 172 def call(input_ids, batched_logits) # NOTE: This is different from the Python code, since vanilla Ruby does not support vectorized operations. # As a result, we apply each processor to each item in the batch. batched_logits.each do |logits| # Modifies logits inplace @processors.each do |func| func.(input_ids, logits) end end end |
#concat(items) ⇒ Object
168 169 170 |
# File 'lib/informers/utils/generation.rb', line 168 def concat(items) @processors.concat(items) end |
#push(item) ⇒ Object
164 165 166 |
# File 'lib/informers/utils/generation.rb', line 164 def push(item) @processors << item end |
#to_ary ⇒ Object
183 184 185 |
# File 'lib/informers/utils/generation.rb', line 183 def to_ary @processors end |