-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced task classes with pipeline method and added Model class
- Loading branch information
Showing
48 changed files
with
1,526 additions
and
1,252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,19 +3,18 @@ require_relative "lib/informers/version" | |
Gem::Specification.new do |spec| | ||
spec.name = "informers" | ||
spec.version = Informers::VERSION | ||
spec.summary = "State-of-the-art natural language processing for Ruby" | ||
spec.summary = "Fast transformer inference for Ruby" | ||
spec.homepage = "https://github.com/ankane/informers" | ||
spec.license = "Apache-2.0" | ||
|
||
spec.author = "Andrew Kane" | ||
spec.email = "[email protected]" | ||
|
||
spec.files = Dir["*.{md,txt}", "{lib,vendor}/**/*"] | ||
spec.files = Dir["*.{md,txt}", "{lib}/**/*"] | ||
spec.require_path = "lib" | ||
|
||
spec.required_ruby_version = ">= 3.1" | ||
|
||
spec.add_dependency "blingfire", ">= 0.1.7" | ||
spec.add_dependency "numo-narray" | ||
spec.add_dependency "onnxruntime", ">= 0.5.1" | ||
spec.add_dependency "onnxruntime", ">= 0.9" | ||
spec.add_dependency "tokenizers", ">= 0.5.2" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
# dependencies | ||
require "blingfire" | ||
require "numo/narray" | ||
require "onnxruntime" | ||
require "tokenizers" | ||
|
||
# stdlib | ||
require "io/console" | ||
require "json" | ||
require "open-uri" | ||
require "stringio" | ||
require "uri" | ||
|
||
# modules | ||
require_relative "informers/feature_extraction" | ||
require_relative "informers/fill_mask" | ||
require_relative "informers/ner" | ||
require_relative "informers/question_answering" | ||
require_relative "informers/sentiment_analysis" | ||
require_relative "informers/text_generation" | ||
require_relative "informers/version" | ||
require_relative "informers/utils/core" | ||
require_relative "informers/utils/hub" | ||
require_relative "informers/utils/math" | ||
require_relative "informers/utils/tensor" | ||
require_relative "informers/configs" | ||
require_relative "informers/env" | ||
require_relative "informers/model" | ||
require_relative "informers/models" | ||
require_relative "informers/tokenizers" | ||
require_relative "informers/pipelines" | ||
|
||
module Informers | ||
class Error < StandardError; end | ||
|
||
class Todo < Error | ||
def message | ||
"not implemented yet" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Informers | ||
class PretrainedConfig | ||
attr_reader :model_type, :problem_type, :id2label | ||
|
||
def initialize(config_json) | ||
@is_encoder_decoder = false | ||
|
||
@model_type = config_json["model_type"] | ||
@problem_type = config_json["problem_type"] | ||
@id2label = config_json["id2label"] | ||
end | ||
|
||
def [](key) | ||
instance_variable_get("@#{key}") | ||
end | ||
|
||
def self.from_pretrained( | ||
pretrained_model_name_or_path, | ||
progress_callback: nil, | ||
config: nil, | ||
cache_dir: nil, | ||
local_files_only: false, | ||
revision: "main", | ||
**kwargs | ||
) | ||
data = config || load_config( | ||
pretrained_model_name_or_path, | ||
progress_callback:, | ||
config:, | ||
cache_dir:, | ||
local_files_only:, | ||
revision: | ||
) | ||
new(data) | ||
end | ||
|
||
def self.load_config(pretrained_model_name_or_path, **options) | ||
info = Utils::Hub.get_model_json(pretrained_model_name_or_path, "config.json", true, **options) | ||
info | ||
end | ||
end | ||
|
||
class AutoConfig | ||
def self.from_pretrained(...) | ||
PretrainedConfig.from_pretrained(...) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Informers | ||
CACHE_HOME = ENV.fetch("XDG_CACHE_HOME", File.join(ENV.fetch("HOME"), ".cache")) | ||
DEFAULT_CACHE_DIR = File.expand_path(File.join(CACHE_HOME, "informers")) | ||
|
||
class << self | ||
attr_accessor :allow_remote_models, :remote_host, :remote_path_template, :cache_dir | ||
end | ||
|
||
self.allow_remote_models = ENV["INFORMERS_OFFLINE"].to_s.empty? | ||
self.remote_host = "https://huggingface.co/" | ||
self.remote_path_template = "{model}/resolve/{revision}/" | ||
|
||
self.cache_dir = DEFAULT_CACHE_DIR | ||
end |
Oops, something went wrong.