ruby-spacy 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +71 -110
- data/Gemfile +1 -1
- data/README.md +21 -18
- data/Rakefile +6 -0
- data/docs/syntax_trees.md +15 -11
- data/examples/llm/anthropic_chat.rb +1 -1
- data/examples/openai_integration/openai_completion.rb +2 -3
- data/examples/openai_integration/openai_query_1.rb +2 -3
- data/examples/openai_integration/openai_query_2.rb +2 -3
- data/examples/openai_integration/openai_query_3.rb +2 -3
- data/examples/openai_integration/openai_query_4.rb +2 -3
- data/examples/rsyntaxtree/outputs/tree_ar_projection.png +0 -0
- data/examples/rsyntaxtree/outputs/tree_de_projection.png +0 -0
- data/examples/rsyntaxtree/outputs/tree_en_chunks.png +0 -0
- data/examples/rsyntaxtree/outputs/tree_en_morphology.png +0 -0
- data/examples/rsyntaxtree/outputs/tree_en_path.png +0 -0
- data/examples/rsyntaxtree/outputs/tree_en_projection.png +0 -0
- data/examples/rsyntaxtree/outputs/tree_ja_chunks.png +0 -0
- data/examples/rsyntaxtree/outputs/tree_ja_projection.png +0 -0
- data/examples/rsyntaxtree/outputs/tree_ru_morphology.png +0 -0
- data/examples/rsyntaxtree/outputs/tree_ru_projection.png +0 -0
- data/examples/rsyntaxtree/outputs/tree_zh_projection.png +0 -0
- data/examples/rsyntaxtree/syntax_tree_ar.rb +1 -1
- data/examples/rsyntaxtree/syntax_tree_de.rb +1 -1
- data/examples/rsyntaxtree/syntax_tree_en.rb +5 -1
- data/examples/rsyntaxtree/syntax_tree_ja.rb +2 -2
- data/examples/rsyntaxtree/syntax_tree_ru.rb +2 -2
- data/examples/rsyntaxtree/syntax_tree_zh.rb +1 -1
- data/lib/ruby-spacy/anthropic_client.rb +8 -7
- data/lib/ruby-spacy/anthropic_helper.rb +15 -7
- data/lib/ruby-spacy/llm_client_base.rb +69 -12
- data/lib/ruby-spacy/openai_client.rb +27 -16
- data/lib/ruby-spacy/openai_helper.rb +12 -7
- data/lib/ruby-spacy/syntax_tree.rb +76 -31
- data/lib/ruby-spacy/version.rb +1 -1
- data/lib/ruby-spacy.rb +66 -36
- data/ruby-spacy.gemspec +8 -1
- metadata +6 -4
- data/.github/FUNDING.yml +0 -6
- data/.github/workflows/ci.yml +0 -97
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8092ed24c921dbc2275034ff35939a762fe14c761322450472f337361a039b87
|
|
4
|
+
data.tar.gz: d6009fc3acbf3bff355fed3e0f556509f081978791e31398f3ee97690224fccc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 27b956204bf65b822b2145628213989202bc4cc6d5af7e5030b41b357402069fef29981ffef3f09585d200197019dedfa905c0caa9af8170b88a1081320ecc65
|
|
7
|
+
data.tar.gz: ebc7aefbba1a330b991de002716eb886c1314b76be7a215d19f0a24453359a9aec0edb3a2f3d9157865e2ca4c6c6b9ae57d7767a388499529feb4fc5297f88c3
|
data/CHANGELOG.md
CHANGED
|
@@ -1,169 +1,130 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 0.8.0 - 2026-11-28
|
|
4
4
|
### Added
|
|
5
|
-
- `
|
|
6
|
-
|
|
7
|
-
`:projection` builds a phrase-structure-like tree from the head words,
|
|
8
|
-
`:chunks` lays the noun chunks out flat. Noun chunks are shaded, named
|
|
9
|
-
entities that coincide with one are labeled, and `morphology: true` attaches
|
|
10
|
-
a table of features to every leaf. rsyntaxtree (>= 2.4.0) is an optional
|
|
11
|
-
dependency, required on first use rather than at load time
|
|
12
|
-
- `Language.new(py_nlp:)` — wrap a Python pipeline built elsewhere, for the
|
|
13
|
-
languages spaCy ships no trained model for. Every right-to-left language is
|
|
14
|
-
one of them, and their trees are drawn mirrored so the leaves run in reading
|
|
15
|
-
order. A package such as spacy-stanza builds the pipeline; ruby-spacy gains
|
|
16
|
-
no dependency
|
|
17
|
-
- `docs/syntax_trees.md` — a gallery of trees in six languages, generated by
|
|
18
|
-
the scripts in `examples/rsyntaxtree/`
|
|
5
|
+
- `path:` in `syntax_tree` — draws the route between two tokens in a heavier line
|
|
6
|
+
- `reasoning_effort:` for OpenAI and `effort:` for Anthropic, per block or per call
|
|
19
7
|
|
|
20
8
|
### Changed
|
|
21
|
-
-
|
|
22
|
-
|
|
23
|
-
|
|
9
|
+
- Default models are now `gpt-6-luna` and `claude-sonnet-5-5`; the previous default `gpt-5-mini` is retired on 2026-12-11
|
|
10
|
+
- Default output limit raised to 4000 tokens, since reasoning counts toward it
|
|
11
|
+
- Syntax trees line up the words on the bottom row; `leaf_align: "off", leafstyle: "nothing"` restores the previous drawing
|
|
12
|
+
- `syntax_tree` requires rsyntaxtree 2.10.0 or later
|
|
13
|
+
- Models that reject `reasoning_effort` are retried without it, as with `temperature`
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- API keys no longer appear in `inspect` output or error messages
|
|
17
|
+
- `Retry-After` waits are capped at 60 seconds and HTTP dates are honored
|
|
18
|
+
- `openai_query` answers every tool call, and `get_tokens` analyzes the text the model asks about
|
|
19
|
+
- Syntax tree options given as Symbols, `corner_label`, and `direction: "ltr"` for right-to-left languages work as documented
|
|
20
|
+
|
|
21
|
+
## 0.7.0 - 2026-09-03
|
|
22
|
+
### Added
|
|
23
|
+
- `Doc#syntax_tree` and `Span#syntax_tree` — render a parse as rsyntaxtree notation, SVG, PNG, PDF, TikZ, or JSON
|
|
24
|
+
- `Language.new(py_nlp:)` — wrap a Python pipeline built elsewhere, such as one from spacy-stanza
|
|
25
|
+
- `docs/syntax_trees.md` — a gallery of syntax trees in six languages
|
|
24
26
|
|
|
25
27
|
## 0.6.0 - 2026-08-31
|
|
26
28
|
### Added
|
|
27
|
-
- GitHub Actions CI — Ruby 3.2 to 4.0 (plus ruby-head) and Python 3.11 to 3.14,
|
|
28
|
-
with a weekly run to catch breakage from new spaCy or PyCall releases
|
|
29
29
|
- `:label` in `Matcher#match` results — the label string of the matched pattern
|
|
30
30
|
|
|
31
31
|
### Changed
|
|
32
|
-
- PyCall 1.5.3 or later is
|
|
33
|
-
process when Ruby's GC releases a Python object on a non-main thread, which
|
|
34
|
-
affects any threaded application (Rails, Puma, Sidekiq)
|
|
32
|
+
- PyCall 1.5.3 or later is required; earlier versions can freeze threaded applications
|
|
35
33
|
- Minimum Ruby version raised to 3.2
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
- Language
|
|
39
|
-
|
|
40
|
-
- `Language.new(timeout:)` now actually fires. The wait happens on a Python
|
|
41
|
-
thread rather than through Ruby's `Timeout`, whose watcher thread cannot run
|
|
42
|
-
while PyCall holds the GVL. `timeout: nil` waits indefinitely, and a timeout
|
|
43
|
-
is never retried
|
|
44
|
-
- README documents the thread-safety constraint: all spaCy calls must be made
|
|
45
|
-
from the thread that initialized PyCall
|
|
34
|
+
- The `numpy` gem is no longer a dependency
|
|
35
|
+
- `terminal-table` requirement relaxed to `>= 3.0, < 5`
|
|
36
|
+
- A `Language` no longer keeps its pipeline alive until the process exits
|
|
37
|
+
- README documents that all spaCy calls must come from the thread that initialized PyCall
|
|
46
38
|
|
|
47
39
|
### Deprecated
|
|
48
|
-
- `Language#spacy_nlp_id` — use `#py_nlp` instead
|
|
49
|
-
but creates a Python global variable that is never released
|
|
40
|
+
- `Language#spacy_nlp_id` — use `#py_nlp` instead
|
|
50
41
|
|
|
51
42
|
### Fixed
|
|
52
|
-
- `
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
which accepts large ids again
|
|
56
|
-
- Integer attributes reached through `method_missing`, such as `Token#orth`,
|
|
57
|
-
were silently corrupted for the same reason: 7 of 12 common words returned a
|
|
58
|
-
negative `orth`. They are now fetched safely, which also restores
|
|
59
|
-
`Token#rank` for out-of-vocabulary tokens
|
|
43
|
+
- `Language.new(timeout:)` now times out; `timeout: nil` waits indefinitely
|
|
44
|
+
- `Matcher#match` returns the correct `:match_id` for every label
|
|
45
|
+
- Large integer attributes such as `Token#orth` and `Token#rank` are no longer corrupted
|
|
60
46
|
|
|
61
47
|
## 0.5.0 - 2026-07-21
|
|
62
48
|
### Added
|
|
63
|
-
- `Language#with_llm(provider:)` —
|
|
64
|
-
|
|
65
|
-
- `
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
- `base_url:` option for OpenAI client/helper — works with any
|
|
69
|
-
OpenAI-compatible server (Ollama, LM Studio, llama.cpp server, vLLM,
|
|
70
|
-
OpenRouter, etc.)
|
|
71
|
-
- `schema:` option for `chat` — Structured Outputs on both providers;
|
|
72
|
-
returns a validated, parsed Ruby Hash
|
|
73
|
-
- New examples under `examples/llm/` (Anthropic, local Ollama, and a
|
|
74
|
-
spaCy-vs-LLM NER comparison with structured outputs)
|
|
49
|
+
- `Language#with_llm(provider:)` — block API for `:openai`, `:anthropic`, and `:ollama`
|
|
50
|
+
- `AnthropicHelper` and `AnthropicClient` — Anthropic Messages API support (requires `ANTHROPIC_API_KEY`)
|
|
51
|
+
- `base_url:` for the OpenAI client and helper — works with any OpenAI-compatible server
|
|
52
|
+
- `schema:` in `chat` — Structured Outputs on both providers, returned as a parsed Hash
|
|
53
|
+
- Examples in `examples/llm/`
|
|
75
54
|
|
|
76
55
|
### Changed
|
|
77
|
-
- `temperature` is
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
models that supported it (also from `Doc#openai_query` /
|
|
82
|
-
`Doc#openai_completion`); now the API default applies unless you pass
|
|
83
|
-
`temperature:` yourself
|
|
84
|
-
- Shared HTTP layer (`LLMClientBase`) extracted from `OpenAIClient`;
|
|
85
|
-
no behavior change for existing OpenAI usage
|
|
86
|
-
- Truncated responses (`finish_reason: length` / `stop_reason: max_tokens`)
|
|
87
|
-
now emit a warning; with `schema:`, unparseable (e.g. truncated) JSON
|
|
88
|
-
returns nil with a warning instead of raising `JSON::ParserError`
|
|
89
|
-
- LLM error messages are printed to stderr (`Kernel#warn`) instead of
|
|
90
|
-
stdout, keeping stdout clean for program output
|
|
91
|
-
- Default model names are now public constants:
|
|
92
|
-
`OpenAIClient::DEFAULT_MODEL`, `OpenAIClient::DEFAULT_EMBEDDINGS_MODEL`,
|
|
93
|
-
`AnthropicClient::DEFAULT_MODEL`
|
|
56
|
+
- `temperature` is sent only when given (previously 0.7 by default); a model that rejects it is retried without it
|
|
57
|
+
- Truncated responses emit a warning; with `schema:`, unparseable JSON returns nil instead of raising
|
|
58
|
+
- LLM error messages go to stderr instead of stdout
|
|
59
|
+
- Default model names are public constants: `OpenAIClient::DEFAULT_MODEL`, `OpenAIClient::DEFAULT_EMBEDDINGS_MODEL`, `AnthropicClient::DEFAULT_MODEL`
|
|
94
60
|
|
|
95
61
|
## 0.4.1 - 2026-07-19
|
|
96
62
|
### Fixed
|
|
97
|
-
-
|
|
98
|
-
are world-readable (0644 / 0755). Version 0.4.0 shipped 11 owner-only
|
|
99
|
-
(0600) files, which made the gem unusable after `sudo gem install`
|
|
63
|
+
- Packaged files are world-readable, so the gem works after `sudo gem install`
|
|
100
64
|
|
|
101
65
|
## 0.4.0 - 2026-02-23
|
|
102
66
|
### Added
|
|
103
|
-
- `Language#with_openai` block API with `OpenAIHelper`
|
|
104
|
-
- `Doc#linguistic_summary`
|
|
105
|
-
- `Token#idx`, `Span#text
|
|
106
|
-
|
|
107
|
-
### Fixed
|
|
108
|
-
- `Doc#ents` returns proper `Span` objects instead of raw Python objects
|
|
67
|
+
- `Language#with_openai` — block API with `OpenAIHelper`
|
|
68
|
+
- `Doc#linguistic_summary` — spaCy analysis as JSON
|
|
69
|
+
- `Token#idx`, `Span#text`, `Span#to_s`, and `Language#memory_zone` (spaCy 3.8+)
|
|
109
70
|
|
|
110
71
|
### Changed
|
|
111
|
-
-
|
|
112
|
-
- OpenAI client
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
-
|
|
116
|
-
|
|
117
|
-
|
|
72
|
+
- `Language.new` validates the model name
|
|
73
|
+
- OpenAI client retries on 429 and supports `dimensions:` and `response_format:`
|
|
74
|
+
- `openai_query` limits the depth of tool calls
|
|
75
|
+
- `respond_to?` reports the Python methods each wrapper forwards
|
|
76
|
+
- `base64` gem added as a dependency (required for Ruby 3.4+)
|
|
77
|
+
|
|
78
|
+
### Fixed
|
|
79
|
+
- `Doc#ents` returns `Span` objects instead of raw Python objects
|
|
118
80
|
|
|
119
81
|
## 0.3.0 - 2025-01-06
|
|
120
82
|
### Added
|
|
121
83
|
- Ruby 4.0 support
|
|
122
|
-
- `Doc#to_bytes`
|
|
123
|
-
- `
|
|
124
|
-
- `PhraseMatcher` class for efficient phrase matching
|
|
125
|
-
- `Language#phrase_matcher` helper method
|
|
84
|
+
- `Doc#to_bytes` and `Doc.from_bytes` — serialize and restore documents
|
|
85
|
+
- `PhraseMatcher` and `Language#phrase_matcher`
|
|
126
86
|
|
|
127
87
|
### Changed
|
|
128
|
-
-
|
|
129
|
-
-
|
|
130
|
-
-
|
|
131
|
-
-
|
|
132
|
-
- Added `fiddle` gem dependency (required for Ruby 4.0)
|
|
88
|
+
- The `ruby-openai` gem is replaced by a built-in OpenAI client
|
|
89
|
+
- Default OpenAI model is now `gpt-5-mini`, and the embeddings model `text-embedding-3-small`
|
|
90
|
+
- `max_tokens:` is renamed `max_completion_tokens:`; the old name still works
|
|
91
|
+
- `fiddle` gem added as a dependency (required for Ruby 4.0)
|
|
133
92
|
|
|
134
93
|
## 0.2.4 - 2024-12-11
|
|
135
94
|
### Changed
|
|
136
|
-
-
|
|
95
|
+
- `Language.new` retries when loading the model fails
|
|
137
96
|
|
|
138
97
|
## 0.2.3 - 2024-08-27
|
|
139
|
-
|
|
140
|
-
-
|
|
98
|
+
### Added
|
|
99
|
+
- `timeout:` in `Language.new`
|
|
100
|
+
|
|
101
|
+
### Changed
|
|
102
|
+
- Default OpenAI model is now `gpt-4o-mini`
|
|
141
103
|
|
|
142
104
|
## 0.2.0 - 2022-10-02
|
|
143
105
|
### Added
|
|
144
|
-
- spaCy 3.7.0
|
|
145
|
-
- `Doc#openai_query`
|
|
146
|
-
- `Doc#openai_completion`
|
|
147
|
-
- `Doc#openai_embeddings`
|
|
106
|
+
- spaCy 3.7.0 support
|
|
107
|
+
- `Doc#openai_query`, `Doc#openai_completion`, and `Doc#openai_embeddings`
|
|
148
108
|
|
|
149
109
|
## 0.1.4.1 - 2021-07-06
|
|
150
|
-
|
|
151
|
-
- `
|
|
110
|
+
### Changed
|
|
111
|
+
- `Language#most_similar` returns hash-based objects that accept method calls
|
|
152
112
|
|
|
153
113
|
## 0.1.4 - 2021-06-26
|
|
154
114
|
### Added
|
|
155
115
|
- `Spacy::Lexeme` class
|
|
156
116
|
|
|
157
|
-
- `Spacy::Token#morpheme` method
|
|
158
117
|
## 0.1.3 - 2021-06-26
|
|
159
|
-
|
|
118
|
+
### Changed
|
|
119
|
+
- No user-facing changes
|
|
160
120
|
|
|
161
121
|
## 0.1.2 - 2021-06-26
|
|
162
122
|
### Added
|
|
163
|
-
- `
|
|
123
|
+
- `Token#morpheme`
|
|
164
124
|
|
|
165
125
|
## 0.1.1 - 2021-06-26
|
|
166
|
-
|
|
126
|
+
### Changed
|
|
127
|
+
- Gem description corrected
|
|
167
128
|
|
|
168
129
|
## 0.1.0 - 2021-06-26
|
|
169
130
|
- Initial release
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
| ✅ | Access to pre-trained word vectors |
|
|
15
15
|
| ✅ | LLM integration: OpenAI, Anthropic (Claude), and local models |
|
|
16
16
|
|
|
17
|
-
Current Version: `0.
|
|
17
|
+
Current Version: `0.8.0`
|
|
18
18
|
|
|
19
19
|
- Ruby 3.2 to 4.0 supported (PyCall 1.5.3 or later required)
|
|
20
20
|
- spaCy 3.8 supported
|
|
@@ -25,7 +25,7 @@ Current Version: `0.7.0`
|
|
|
25
25
|
|
|
26
26
|
## Installation of Prerequisites
|
|
27
27
|
|
|
28
|
-
**IMPORTANT**: Make sure that the `enable-shared` option is enabled in your Python installation. You can use [pyenv](https://github.com/pyenv/pyenv) to install any version of Python you like. spaCy 3.8 supports Python 3.10 and later (wheels are provided for Python 3.10–3.
|
|
28
|
+
**IMPORTANT**: Make sure that the `enable-shared` option is enabled in your Python installation. You can use [pyenv](https://github.com/pyenv/pyenv) to install any version of Python you like. spaCy 3.8 supports Python 3.10 and later (wheels are provided for Python 3.10–3.15), so we recommend using one of those versions. Install Python 3.13, for instance, using pyenv with `enable-shared` as follows:
|
|
29
29
|
|
|
30
30
|
```shell
|
|
31
31
|
$ env CONFIGURE_OPTS="--enable-shared" pyenv install 3.13
|
|
@@ -304,7 +304,7 @@ Output:
|
|
|
304
304
|
|
|
305
305
|
→ [rsyntaxtree](https://github.com/yohasebe/rsyntaxtree)
|
|
306
306
|
|
|
307
|
-
`Doc#syntax_tree` (and `Span#syntax_tree`) converts the parse into rsyntaxtree bracket notation and can render it as an image. rsyntaxtree (>= 2.
|
|
307
|
+
`Doc#syntax_tree` (and `Span#syntax_tree`) converts the parse into rsyntaxtree bracket notation and can render it as an image. rsyntaxtree (>= 2.10.0) is an optional dependency: `gem install rsyntaxtree`.
|
|
308
308
|
|
|
309
309
|
```ruby
|
|
310
310
|
require "ruby-spacy"
|
|
@@ -316,6 +316,7 @@ doc.syntax_tree # => "[S [%NP [DET The] [ADJ quick] ...
|
|
|
316
316
|
File.binwrite("tree.png", doc.syntax_tree(format: :png))
|
|
317
317
|
doc.syntax_tree(style: :chunks) # shallow tree with noun chunks
|
|
318
318
|
doc.syntax_tree(morphology: true) # attach morphology tables to the leaves
|
|
319
|
+
doc.syntax_tree(format: :svg, path: [doc[3], doc[11]]) # highlight the route from "fox" to "river"
|
|
319
320
|
```
|
|
320
321
|
|
|
321
322
|
<img src="https://github.com/yohasebe/ruby-spacy/blob/main/examples/rsyntaxtree/outputs/tree_en_projection.png" alt="English projection tree" width="560">
|
|
@@ -324,11 +325,11 @@ doc.syntax_tree(morphology: true) # attach morphology tables to the leave
|
|
|
324
325
|
|
|
325
326
|
<img src="https://github.com/yohasebe/ruby-spacy/blob/main/examples/rsyntaxtree/outputs/tree_ja_projection.png" alt="Japanese projection tree with named entities" width="500">
|
|
326
327
|
|
|
327
|
-
Two styles are available: `:projection` (default; a phrase-structure-like tree projected from the head words) and `:chunks` (a shallow tree with noun chunks). In both, noun chunks are shaded grey, and a chunk that is also a named entity is shaded orange and labeled with the entity type (`entities: false` to disable). The blue and green are rsyntaxtree's default palette, not marking of any kind; only the shading carries meaning. Punctuation is omitted (`punctuation: true` to keep it). The `format:` option accepts `:bracket` (default), `:svg`, `:png`, `:pdf`, `:tikz`, and `:json`; any other keywords are passed through to rsyntaxtree (e.g. `fontsize: 12`).
|
|
328
|
+
Two styles are available: `:projection` (default; a phrase-structure-like tree projected from the head words) and `:chunks` (a shallow tree with noun chunks). In both, noun chunks are shaded grey, and a chunk that is also a named entity is shaded orange and labeled with the entity type (`entities: false` to disable). The blue and green are rsyntaxtree's default palette, not marking of any kind; only the shading carries meaning. Punctuation is omitted (`punctuation: true` to keep it). The words line up on the bottom row, each joined to its tag by a dashed line (`leaf_align: "off", leafstyle: "nothing"` to set each word directly under its tag). `path:` takes two tokens and draws the route between them through the tree in a heavier line; in a projection tree, that route is the dependency path between the two words. The `format:` option accepts `:bracket` (default), `:svg`, `:png`, `:pdf`, `:tikz`, and `:json`; any other keywords are passed through to rsyntaxtree (e.g. `fontsize: 12`).
|
|
328
329
|
|
|
329
330
|
The notation is rsyntaxtree-flavored: it can contain AVMs (`#(...#)`), region backgrounds (`%`), and in-word space joins (`<>`). A doc must hold a single sentence; for a multi-sentence doc, use `doc.sents.map { |s| s.syntax_tree }`.
|
|
330
331
|
|
|
331
|
-
**Annotation schemes differ between models.** spaCy's English models make the preposition the head of its phrase, so projection trees contain `PP` nodes. UD-style models (Japanese, Russian, Chinese, and most others) attach prepositions and particles to the noun instead, so no `PP` appears.
|
|
332
|
+
**Annotation schemes differ between models.** spaCy's English models make the preposition the head of its phrase, so projection trees contain `PP` nodes. UD-style models (Japanese, Russian, Chinese, and most others) attach prepositions and particles to the noun instead, so a case-marked phrase is labeled `NP` and no `PP` appears. The labels are ruby-spacy's own, derived from the head's POS tag — spaCy supplies only tags and dependencies.
|
|
332
333
|
|
|
333
334
|
**Entity highlighting requires noun chunks.** An entity gets its colored background only where it coincides with a noun chunk. In languages whose models have no noun chunk iterator (Russian, Chinese, Korean, Polish, ...) `entities: true` highlights nothing and `style: :chunks` raises `ArgumentError`.
|
|
334
335
|
|
|
@@ -690,8 +691,8 @@ nlp = Spacy::Language.new("en_core_web_sm")
|
|
|
690
691
|
doc = nlp.read("The Beatles released 12 studio albums")
|
|
691
692
|
|
|
692
693
|
# default parameter values
|
|
693
|
-
# max_completion_tokens:
|
|
694
|
-
# model: "gpt-
|
|
694
|
+
# max_completion_tokens: 4000
|
|
695
|
+
# model: "gpt-6-luna"
|
|
695
696
|
res1 = doc.openai_query(
|
|
696
697
|
access_token: api_key,
|
|
697
698
|
prompt: "Translate the text to Japanese."
|
|
@@ -715,8 +716,8 @@ nlp = Spacy::Language.new("en_core_web_sm")
|
|
|
715
716
|
doc = nlp.read("The Beatles were an English rock band formed in Liverpool in 1960.")
|
|
716
717
|
|
|
717
718
|
# default parameter values
|
|
718
|
-
# max_completion_tokens:
|
|
719
|
-
# model: "gpt-
|
|
719
|
+
# max_completion_tokens: 4000
|
|
720
|
+
# model: "gpt-6-luna"
|
|
720
721
|
res = doc.openai_query(
|
|
721
722
|
access_token: api_key,
|
|
722
723
|
prompt: "Extract the topic of the document and list 10 entities (names, concepts, locations, etc.) that are relevant to the topic."
|
|
@@ -752,8 +753,8 @@ nlp = Spacy::Language.new("en_core_web_sm")
|
|
|
752
753
|
doc = nlp.read("The Beatles released 12 studio albums")
|
|
753
754
|
|
|
754
755
|
# default parameter values
|
|
755
|
-
# max_completion_tokens:
|
|
756
|
-
# model: "gpt-
|
|
756
|
+
# max_completion_tokens: 4000
|
|
757
|
+
# model: "gpt-6-luna"
|
|
757
758
|
res = doc.openai_query(
|
|
758
759
|
access_token: api_key,
|
|
759
760
|
prompt: "List token data of each of the words used in the sentence. Add 'meaning' property and value (brief semantic definition) to each token data. Output as a JSON object."
|
|
@@ -841,8 +842,8 @@ nlp = Spacy::Language.new("en_core_web_sm")
|
|
|
841
842
|
doc = nlp.read("The Beatles released 12 studio albums")
|
|
842
843
|
|
|
843
844
|
# default parameter values
|
|
844
|
-
# max_completion_tokens:
|
|
845
|
-
# model: "gpt-
|
|
845
|
+
# max_completion_tokens: 4000
|
|
846
|
+
# model: "gpt-6-luna"
|
|
846
847
|
res = doc.openai_query(
|
|
847
848
|
access_token: api_key,
|
|
848
849
|
prompt: "Generate a tree diagram from the text using given token data. Use the following bracketing style: [S [NP [Det the] [N cat]] [VP [V sat] [PP [P on] [NP the mat]]]"
|
|
@@ -883,8 +884,8 @@ nlp = Spacy::Language.new("en_core_web_sm")
|
|
|
883
884
|
doc = nlp.read("Vladimir Nabokov was a")
|
|
884
885
|
|
|
885
886
|
# default parameter values
|
|
886
|
-
# max_completion_tokens:
|
|
887
|
-
# model: "gpt-
|
|
887
|
+
# max_completion_tokens: 4000
|
|
888
|
+
# model: "gpt-6-luna"
|
|
888
889
|
res = doc.openai_completion(access_token: api_key)
|
|
889
890
|
puts res
|
|
890
891
|
```
|
|
@@ -933,7 +934,7 @@ require "ruby-spacy"
|
|
|
933
934
|
nlp = Spacy::Language.new("en_core_web_sm")
|
|
934
935
|
doc = nlp.read("Apple Inc. was founded by Steve Jobs in California.")
|
|
935
936
|
|
|
936
|
-
nlp.with_openai(model: "gpt-
|
|
937
|
+
nlp.with_openai(model: "gpt-6-luna") do |ai|
|
|
937
938
|
result = ai.chat(
|
|
938
939
|
system: "You are a linguistic analyst. Analyze the given linguistic data.",
|
|
939
940
|
user: doc.linguistic_summary
|
|
@@ -950,7 +951,7 @@ require "ruby-spacy"
|
|
|
950
951
|
nlp = Spacy::Language.new("en_core_web_sm")
|
|
951
952
|
texts = ["The bank approved the loan.", "I sat on the river bank."]
|
|
952
953
|
|
|
953
|
-
nlp.with_openai(model: "gpt-
|
|
954
|
+
nlp.with_openai(model: "gpt-6-luna") do |ai|
|
|
954
955
|
nlp.pipe(texts).each do |doc|
|
|
955
956
|
result = ai.chat(
|
|
956
957
|
system: "Identify the meaning of 'bank' in one word based on the linguistic context.",
|
|
@@ -988,7 +989,7 @@ The `Language#with_llm` block API generalizes `with_openai` to multiple provider
|
|
|
988
989
|
|
|
989
990
|
```ruby
|
|
990
991
|
# Requires the ANTHROPIC_API_KEY environment variable
|
|
991
|
-
# Default model: claude-sonnet-5 (override with model: "...")
|
|
992
|
+
# Default model: claude-sonnet-5-5 (override with model: "...")
|
|
992
993
|
nlp.with_llm(provider: :anthropic) do |ai|
|
|
993
994
|
result = ai.chat(
|
|
994
995
|
system: "You are a linguistic analyst.",
|
|
@@ -1044,6 +1045,8 @@ result["entities"].each { |ent| puts "#{ent["text"]} (#{ent["label"]})" }
|
|
|
1044
1045
|
|
|
1045
1046
|
**Note on `temperature`:** for all providers, `temperature` is omitted from requests unless you pass it explicitly (`ai.chat(user: "...", temperature: 0.3)`). Models that reject the parameter (e.g., GPT-5 series, o-series, and current Claude models) are automatically retried once without it, so any model works without per-model configuration.
|
|
1046
1047
|
|
|
1048
|
+
**Reasoning and token limits:** reasoning models count the tokens they spend reasoning toward the response limit, which defaults to 4000 (`max_tokens:`, or `max_completion_tokens:` for OpenAI). To set how much they reason, pass `reasoning_effort:` for OpenAI (`"none"`, `"low"`, `"medium"`, `"high"`, ...) or `effort:` for Anthropic (`"low"` to `"max"`), either when opening the block or per `chat` call. `Doc#openai_query` sends `reasoning_effort: "none"`, which models such as `gpt-6-luna` require to call its `get_tokens` tool through Chat Completions; pass another value, or `nil` to leave it out, for a model that rejects it.
|
|
1049
|
+
|
|
1047
1050
|
See `examples/llm/` for complete scripts, including a spaCy-vs-LLM NER comparison.
|
|
1048
1051
|
|
|
1049
1052
|
## Advanced Usage
|
data/Rakefile
CHANGED
|
@@ -23,3 +23,9 @@ task :normalize_permissions do
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
Rake::Task["build"].enhance([:normalize_permissions])
|
|
26
|
+
|
|
27
|
+
# Inspect the built gem before it can be pushed: its payload must match
|
|
28
|
+
# spec.files in both directions, and must carry no secrets, machine-local
|
|
29
|
+
# paths, or owner-only modes. `release` depends on `build`, so this is the
|
|
30
|
+
# last thing that runs before a push.
|
|
31
|
+
Rake::Task["build"].enhance { sh "ruby", "scripts/verify_gem.rb" }
|
data/docs/syntax_trees.md
CHANGED
|
@@ -2,54 +2,58 @@
|
|
|
2
2
|
|
|
3
3
|
Trees drawn by `Doc#syntax_tree` with the [rsyntaxtree](https://github.com/yohasebe/rsyntaxtree) gem. The scripts in `examples/rsyntaxtree/` generate every image here.
|
|
4
4
|
|
|
5
|
-
Noun chunks are shaded grey; a chunk that is also a named entity is shaded orange and labeled with the entity type. The blue and green are rsyntaxtree's default palette, not marking of any kind. Phrase labels
|
|
5
|
+
Noun chunks are shaded grey; a chunk that is also a named entity is shaded orange and labeled with the entity type. The words line up on the bottom row, each joined to its tag by a dashed line. The blue and green are rsyntaxtree's default palette, not marking of any kind. Phrase labels are ruby-spacy's own, derived from the head's POS tag, so they follow whatever annotation scheme the model uses. Both are explained in the [README](../README.md#syntax-trees).
|
|
6
6
|
|
|
7
7
|
## English (`en_core_web_sm`)
|
|
8
8
|
|
|
9
9
|
Projection, the default style:
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
<img src="https://github.com/yohasebe/ruby-spacy/blob/main/examples/rsyntaxtree/outputs/tree_en_projection.png" alt="English projection" width="769">
|
|
12
12
|
|
|
13
13
|
Chunks style:
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
<img src="https://github.com/yohasebe/ruby-spacy/blob/main/examples/rsyntaxtree/outputs/tree_en_chunks.png" alt="English chunks" width="739">
|
|
16
|
+
|
|
17
|
+
A highlighted path (`path: [doc[3], doc[11]]`), the dependency path from "fox" to "river":
|
|
18
|
+
|
|
19
|
+
<img src="https://github.com/yohasebe/ruby-spacy/blob/main/examples/rsyntaxtree/outputs/tree_en_path.png" alt="English path" width="769">
|
|
16
20
|
|
|
17
21
|
With morphology (a shorter sentence — the tables are tall):
|
|
18
22
|
|
|
19
|
-
|
|
23
|
+
<img src="https://github.com/yohasebe/ruby-spacy/blob/main/examples/rsyntaxtree/outputs/tree_en_morphology.png" alt="English morphology" width="900">
|
|
20
24
|
|
|
21
25
|
## Japanese (`ja_core_news_sm`)
|
|
22
26
|
|
|
23
27
|
Projection, with PERSON and GPE highlighted:
|
|
24
28
|
|
|
25
|
-
|
|
29
|
+
<img src="https://github.com/yohasebe/ruby-spacy/blob/main/examples/rsyntaxtree/outputs/tree_ja_projection.png" alt="Japanese projection" width="737">
|
|
26
30
|
|
|
27
31
|
Chunks style:
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
<img src="https://github.com/yohasebe/ruby-spacy/blob/main/examples/rsyntaxtree/outputs/tree_ja_chunks.png" alt="Japanese chunks" width="752">
|
|
30
34
|
|
|
31
35
|
## Russian (`ru_core_news_sm`)
|
|
32
36
|
|
|
33
37
|
No noun chunk iterator, so `style: :chunks` is unavailable.
|
|
34
38
|
|
|
35
|
-
|
|
39
|
+
<img src="https://github.com/yohasebe/ruby-spacy/blob/main/examples/rsyntaxtree/outputs/tree_ru_projection.png" alt="Russian projection" width="574">
|
|
36
40
|
|
|
37
41
|
With morphology — Russian marks case, gender, animacy, aspect, and voice:
|
|
38
42
|
|
|
39
|
-
|
|
43
|
+
<img src="https://github.com/yohasebe/ruby-spacy/blob/main/examples/rsyntaxtree/outputs/tree_ru_morphology.png" alt="Russian morphology" width="900">
|
|
40
44
|
|
|
41
45
|
## German (`de_core_news_sm`)
|
|
42
46
|
|
|
43
|
-
|
|
47
|
+
<img src="https://github.com/yohasebe/ruby-spacy/blob/main/examples/rsyntaxtree/outputs/tree_de_projection.png" alt="German projection" width="580">
|
|
44
48
|
|
|
45
49
|
## Chinese (`zh_core_web_sm`)
|
|
46
50
|
|
|
47
51
|
No noun chunk iterator, so `style: :chunks` is unavailable.
|
|
48
52
|
|
|
49
|
-
|
|
53
|
+
<img src="https://github.com/yohasebe/ruby-spacy/blob/main/examples/rsyntaxtree/outputs/tree_zh_projection.png" alt="Chinese projection" width="655">
|
|
50
54
|
|
|
51
55
|
## Arabic (right-to-left)
|
|
52
56
|
|
|
53
57
|
spaCy ships no Arabic pipeline, so this tree was parsed with [Stanza](https://stanfordnlp.github.io/stanza/) via [spacy-stanza](https://github.com/explosion/spacy-stanza) and wrapped with `Spacy::Language.new(py_nlp:)`. Right-to-left languages are drawn mirrored automatically. This pipeline has no noun chunks, so nothing is shaded. See `examples/rsyntaxtree/syntax_tree_ar.rb`.
|
|
54
58
|
|
|
55
|
-
|
|
59
|
+
<img src="https://github.com/yohasebe/ruby-spacy/blob/main/examples/rsyntaxtree/outputs/tree_ar_projection.png" alt="Arabic projection" width="438">
|
|
@@ -6,7 +6,7 @@ $LOAD_PATH.unshift(File.expand_path("../../lib", __dir__))
|
|
|
6
6
|
require "ruby-spacy"
|
|
7
7
|
|
|
8
8
|
# Requires the ANTHROPIC_API_KEY environment variable
|
|
9
|
-
# Default model: claude-sonnet-5 (override with model: "...")
|
|
9
|
+
# Default model: claude-sonnet-5-5 (override with model: "...")
|
|
10
10
|
|
|
11
11
|
nlp = Spacy::Language.new("en_core_web_sm")
|
|
12
12
|
doc = nlp.read("The cat sat on the mat while the dog slept under the table.")
|
|
@@ -10,9 +10,8 @@ nlp = Spacy::Language.new("en_core_web_sm")
|
|
|
10
10
|
doc = nlp.read("Vladimir Nabokov was a")
|
|
11
11
|
|
|
12
12
|
# default parameter values
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
# model: "gpt-4o-mini"
|
|
13
|
+
# max_completion_tokens: 4000
|
|
14
|
+
# model: "gpt-6-luna"
|
|
16
15
|
res = doc.openai_completion(access_token: api_key)
|
|
17
16
|
puts res
|
|
18
17
|
|
|
@@ -10,9 +10,8 @@ nlp = Spacy::Language.new("en_core_web_sm")
|
|
|
10
10
|
doc = nlp.read("The Beatles released 12 studio albums")
|
|
11
11
|
|
|
12
12
|
# default parameter values
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
# model: "gpt-4o-mini"
|
|
13
|
+
# max_completion_tokens: 4000
|
|
14
|
+
# model: "gpt-6-luna"
|
|
16
15
|
res = doc.openai_query(access_token: api_key, prompt: "Translate the text to Japanese.")
|
|
17
16
|
|
|
18
17
|
puts res
|
|
@@ -10,9 +10,8 @@ nlp = Spacy::Language.new("en_core_web_sm")
|
|
|
10
10
|
doc = nlp.read("The Beatles were an English rock band formed in Liverpool in 1960.")
|
|
11
11
|
|
|
12
12
|
# default parameter values
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
# model: "gpt-4o-mini"
|
|
13
|
+
# max_completion_tokens: 4000
|
|
14
|
+
# model: "gpt-6-luna"
|
|
16
15
|
res = doc.openai_query(access_token: api_key, prompt: "Extract the topic of the document and list 10 entities (names, concepts, locations, etc.) that are relevant to the topic.")
|
|
17
16
|
|
|
18
17
|
puts res
|
|
@@ -10,9 +10,8 @@ nlp = Spacy::Language.new("en_core_web_sm")
|
|
|
10
10
|
doc = nlp.read("The Beatles released 12 studio albums")
|
|
11
11
|
|
|
12
12
|
# default parameter values
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
# model: "gpt-4o-mini"
|
|
13
|
+
# max_completion_tokens: 4000
|
|
14
|
+
# model: "gpt-6-luna"
|
|
16
15
|
res = doc.openai_query(
|
|
17
16
|
access_token: api_key,
|
|
18
17
|
prompt: "List token data of each of the words used in the sentence. Add 'meaning' property and value (brief semantic definition) to each token data. Output as a JSON object.",
|
|
@@ -10,9 +10,8 @@ nlp = Spacy::Language.new("en_core_web_sm")
|
|
|
10
10
|
doc = nlp.read("The Beatles released 12 studio albums")
|
|
11
11
|
|
|
12
12
|
# default parameter values
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
# model: "gpt-4o-mini"
|
|
13
|
+
# max_completion_tokens: 4000
|
|
14
|
+
# model: "gpt-6-luna"
|
|
16
15
|
res = doc.openai_query(
|
|
17
16
|
access_token: api_key,
|
|
18
17
|
model: "gpt-4o",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -19,7 +19,7 @@ $LOAD_PATH.unshift(File.expand_path("../../lib", __dir__))
|
|
|
19
19
|
require "ruby-spacy"
|
|
20
20
|
require "fileutils"
|
|
21
21
|
|
|
22
|
-
# Requires the rsyntaxtree gem (>= 2.
|
|
22
|
+
# Requires the rsyntaxtree gem (>= 2.10.0): gem install rsyntaxtree
|
|
23
23
|
|
|
24
24
|
py_nlp = PyCall.import_module("spacy_stanza")
|
|
25
25
|
.load_pipeline("ar", processors: "tokenize,pos,lemma,depparse", verbose: false)
|
|
@@ -6,7 +6,7 @@ $LOAD_PATH.unshift(File.expand_path("../../lib", __dir__))
|
|
|
6
6
|
require "ruby-spacy"
|
|
7
7
|
require "fileutils"
|
|
8
8
|
|
|
9
|
-
# Requires the rsyntaxtree gem (>= 2.
|
|
9
|
+
# Requires the rsyntaxtree gem (>= 2.10.0): gem install rsyntaxtree
|
|
10
10
|
|
|
11
11
|
nlp = Spacy::Language.new("de_core_news_sm")
|
|
12
12
|
doc = nlp.read("Der alte Professor las gestern ein interessantes Buch.")
|