@@ -29,9 +29,19 @@ text = "Apple CEO Tim Cook announced iPhone 15 in Cupertino yesterday."
2929labels = [" company" , " person" , " product" , " location" ]
3030
3131model = Gliner [labels]
32- pp model[text]
32+ entities = model[text]
3333
34- # => {"company"=>["Apple"], "person"=>["Tim Cook"], "product"=>["iPhone 15"], "location"=>["Cupertino"]}
34+ pp entities[" person" ]
35+ # => [#<data Gliner::Entity ...>]
36+
37+ entities[" person" ].first.text
38+ # => "Tim Cook"
39+
40+ entities[" person" ].first.confidence
41+ # => 92.4
42+
43+ entities[" person" ].first.offsets
44+ # => [10, 18]
3545```
3646
3747You can also pass per-entity configs:
@@ -43,9 +53,13 @@ labels = {
4353}
4454
4555model = Gliner [labels]
46- pp model[" Email John Doe at john@example.com." , threshold: 0.5 ]
56+ entities = model[" Email John Doe at john@example.com." , threshold: 0.5 ]
4757
48- # => {"email"=>["john@example.com"], "person"=>"John Doe"}
58+ entities[" person" ].text
59+ # => "John Doe"
60+
61+ entities[" email" ].map(& :text )
62+ # => ["john@example.com"]
4963```
5064
5165### Classification
@@ -59,7 +73,30 @@ result = model["This laptop has amazing performance but terrible battery life!"]
5973
6074pp result
6175
62- # => {"sentiment"=>"negative"}
76+ # => {"sentiment"=>#<data Gliner::Label ...>}
77+
78+ result[" sentiment" ].label
79+ # => "negative"
80+
81+ result[" sentiment" ].confidence
82+ # => 87.1
83+ ```
84+
85+ Multiple classification tasks:
86+
87+ ``` ruby
88+ text = " Breaking: Tech giant announces major layoffs amid market downturn"
89+
90+ tasks = {
91+ " sentiment" => %w[positive negative neutral] ,
92+ " urgency" => %w[high medium low] ,
93+ " category" => { " labels" => %w[tech finance politics sports] , " multi_label" => false }
94+ }
95+
96+ results = Gliner .classify[tasks][text]
97+
98+ results.transform_values { |value | value.label }
99+ # => {"sentiment"=>"negative", "urgency"=>"high", "category"=>"tech"}
63100```
64101
65102### Structured extraction
@@ -77,10 +114,21 @@ structure = {
77114}
78115
79116result = Gliner [structure][text]
117+ product = result.fetch(" product" ).first
80118
81119pp result
82120
83- # => {"product"=>[{"name"=>"iPhone 15 Pro Max", "storage"=>"256GB", "processor"=>"A17 Pro", "price"=>"1199"}]}
121+ product[" name" ].text
122+ # => "iPhone 15 Pro Max"
123+
124+ product[" storage" ].text
125+ # => "256GB"
126+
127+ product[" processor" ].text
128+ # => "A17 Pro"
129+
130+ product[" price" ].text
131+ # => "$1199"
84132```
85133
86134Choices can be included in field specs:
0 commit comments