-
Notifications
You must be signed in to change notification settings - Fork 2
add rwth_dbis learner models #284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Krishna-Rani-t
wants to merge
4
commits into
dev
Choose a base branch
from
learner-dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,57 @@ | ||
| # Import core modules from the OntoLearner library | ||
| from ontolearner import LearnerPipeline, train_test_split | ||
| from ontolearner import ChordOntology, RWTHDBISTaxonomyLearner | ||
|
|
||
| # Load the Chord ontology, which exposes hierarchical (parent, child) relations for taxonomy discovery | ||
| ontology = ChordOntology() | ||
| ontology.load() # Read entities, type system, and taxonomic edges into memory | ||
|
|
||
| # Extract typed taxonomic edges and split into train/test while preserving the structured shape | ||
| train_data, test_data = train_test_split( | ||
| ontology.extract(), | ||
| test_size=0.2, | ||
| random_state=42 | ||
| ) | ||
|
|
||
| # Initialize a supervised taxonomy classifier (encoder-based fine-tuning) | ||
| # Negative sampling controls the number of non-edge examples; bidirectional templates create both (p→c) and (c→p) views | ||
| # Context features are optional and can be enabled with with_context=True and a JSON path of type descriptions | ||
| learner = RWTHDBISTaxonomyLearner( | ||
| model_name="microsoft/deberta-v3-small", | ||
| output_dir="./results/", | ||
| num_train_epochs=1, | ||
| per_device_train_batch_size=8, | ||
| gradient_accumulation_steps=4, | ||
| learning_rate=2e-5, | ||
| max_length=256, | ||
| seed=42, | ||
| negative_ratio=5, | ||
| bidirectional_templates=True, | ||
| context_json_path=None, | ||
| ontology_name=ontology.ontology_full_name, | ||
| ) | ||
|
|
||
| # Build the pipeline | ||
| pipeline = LearnerPipeline( | ||
| llm=learner, | ||
| llm_id=learner.model_name, | ||
| ontologizer_data=False, | ||
| ) | ||
|
|
||
| # # Run the full learning pipeline on the taxonomy-discovery task | ||
| outputs = pipeline( | ||
| train_data=train_data, | ||
| test_data=test_data, | ||
| task="taxonomy-discovery", | ||
| evaluate=True, | ||
| ontologizer_data=False, | ||
| ) | ||
|
|
||
| # Display the evaluation results | ||
| print("Metrics:", outputs['metrics']) # Shows {'precision': ..., 'recall': ..., 'f1_score': ...} | ||
|
|
||
| # Display total elapsed time for training + prediction + evaluation | ||
| print("Elapsed time:", outputs['elapsed_time']) | ||
|
|
||
| # Print all returned outputs (include predictions) | ||
| print(outputs) |
This file contains hidden or 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,50 @@ | ||
| # Import core modules from the OntoLearner library | ||
| from ontolearner import LearnerPipeline, train_test_split, AgrO | ||
| from ontolearner import RWTHDBISTermTypingLearner | ||
|
|
||
| #load the AgrO ontology. | ||
| # AgrO provides term-typing supervision where each term can be annotated with one or more types. | ||
| ontology = AgrO() | ||
| ontology.load() | ||
| data = ontology.extract() | ||
|
|
||
| # Split the labeled term-typing data into train and test sets | ||
| train_data, test_data = train_test_split(data, test_size=0.2, random_state=42) | ||
|
|
||
| # Configure a supervised encoder-based classifier for term typing. | ||
| # This fine-tunes DeBERTa v3 on (term → type) signals; increase epochs for stronger results. | ||
| learner = RWTHDBISTermTypingLearner( | ||
| model_name="microsoft/deberta-v3-small", | ||
| output_dir="./results/deberta-v3", | ||
| num_train_epochs=30, | ||
| per_device_train_batch_size=16, | ||
| gradient_accumulation_steps=2, | ||
| learning_rate=2e-5, | ||
| max_length=64, | ||
| seed=42, | ||
| ) | ||
|
|
||
| # Build the pipeline and pass raw structured objects end-to-end. | ||
| pipeline = LearnerPipeline( | ||
| llm=learner, | ||
| llm_id=learner.model_name, | ||
| ontologizer_data=False, | ||
| ) | ||
|
|
||
| # Run the full learning pipeline on the term-typing task | ||
| outputs = pipeline( | ||
| train_data=train_data, | ||
| test_data=test_data, | ||
| task="term-typing", | ||
| evaluate=True, | ||
| ontologizer_data=False, | ||
| ) | ||
|
|
||
| # Display the evaluation results | ||
| print("Metrics:", outputs['metrics']) # Shows {'precision': ..., 'recall': ..., 'f1_score': ...} | ||
|
|
||
| # Display total elapsed time for training + prediction + evaluation | ||
| print("Elapsed time:", outputs['elapsed_time']) | ||
|
|
||
| # Print all returned outputs (include predictions) | ||
| print(outputs) |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -17,3 +17,5 @@ | |
| from .rag import AutoRAGLearner | ||
| from .prompt import StandardizedPrompting | ||
| from .label_mapper import LabelMapper | ||
| from .taxonomy_discovery.rwthdbis import RWTHDBISSFTLearner as RWTHDBISTaxonomyLearner | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using from .taxonomy_discovery import RWTHDBISSFTLearner
|
||
| from .term_typing.rwthdbis import RWTHDBISSFTLearner as RWTHDBISTermTypingLearner | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous line comment also applicable to this line of code as well. |
||
This file contains hidden or 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,15 @@ | ||
| # Copyright (c) 2025 SciKnowOrg | ||
| # | ||
| # Licensed under the MIT License (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://opensource.org/licenses/MIT | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from .rwthdbis import RWTHDBISSFTLearner |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Krishna-Rani-t I see this is becoming problematic! So here is the new idea:
Let's not import the models here! so
or similar works will be removed from this init, and in the ontolearner/init.py you DO NOT NEED to do the following imports:
In your examples, for loading lets say
SKHNLPZSLearner, you will do this:so if you use the same class name inside the
learner/term_typing /it will be