taijainteroperability.jl
A package for enabling interoperability between Python and R machine learning models with Taija.
https://github.com/juliatrustworthyai/taijainteroperability.jl
Science Score: 54.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
1 of 3 committers (33.3%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.6%) to scientific vocabulary
Repository
A package for enabling interoperability between Python and R machine learning models with Taija.
Basic Info
- Host: GitHub
- Owner: JuliaTrustworthyAI
- License: mit
- Language: Julia
- Default Branch: main
- Homepage: https://www.taija.org/TaijaInteroperability.jl/
- Size: 118 KB
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
- Releases: 1
Metadata Files
README.md
TaijaInteroperability
A package for enabling interoperability between Python and R machine learning models with Taija.
Importing PyTorch models
The package combined with CounterfactualExplanations supports generating counterfactuals for any neural network that has been previously defined and trained using PyTorch, regardless of the specific architectural details of the model. To generate counterfactuals for a PyTorch model, save the model inside a .pt file and call the following function:
julia
model_loaded = TaijaInteroperability.pytorch_model_loader(
"$(pwd())/docs/src/tutorials/miscellaneous",
"neural_network_class",
"NeuralNetwork",
"$(pwd())/docs/src/tutorials/miscellaneous/pretrained_model.pt"
)
The method pytorch_model_loader requires four arguments:
1. The path to the folder with a .py file where the PyTorch model is defined
2. The name of the file where the PyTorch model is defined
3. The name of the class of the PyTorch model
4. The path to the Pickle file that holds the model weights
In the above case:
1. The file defining the model is inside $(pwd())/docs/src/tutorials/miscellaneous
2. The name of the .py file holding the model definition is neural_network_class
3. The name of the model class is NeuralNetwork
4. The Pickle file is located at $(pwd())/docs/src/tutorials/miscellaneous/pretrained_model.pt
Though the model file and Pickle file are inside the same directory in this tutorial, this does not necessarily have to be the case.
The reason why the model file and Pickle file have to be provided separately is that the package expects an already trained PyTorch model as input. It is also possible to define new PyTorch models within the package, but since this is not the expected use of the package, special support is not offered for that. A guide for defining Python and PyTorch classes in Julia through PythonCall.jl can be found here.
Once the PyTorch model has been loaded into the package, wrap it inside the PyTorchModel class:
julia
model_pytorch = TaijaInteroperability.PyTorchModel(model_loaded, counterfactual_data.likelihood)
This model can now be passed into the generators like any other as described in the CounterfactualExplanations documentation.
Please note that the functionality for generating counterfactuals for Python models is only available if your Julia version is 1.8 or above. For Julia 1.7 users, we recommend upgrading the version to 1.8 or 1.9 before loading a PyTorch model into the package.
Importing R torch models
Please note that due to the incompatibility between RCall and PythonCall, it is not feasible to test both PyTorch and RTorch implementations within the same pipeline. While the RTorch implementation has been manually tested, we cannot ensure its consistent functionality as it is inherently susceptible to bugs.
The TaijaInteroperability package combined with CounterfactualExplanations package supports generating counterfactuals for neural networks that have been defined and trained using R torch. Regardless of the specific architectural details of the model, you can easily generate counterfactual explanations by following these steps.
Saving the R torch model
First, save your trained R torch model as a .pt file using the torch_save() function provided by the R torch library. This function allows you to serialize the model and save it to a file. For example:
r
torch_save(model, file = "$(pwd())/docs/src/tutorials/miscellaneous/r_model.pt")
Make sure to specify the correct file path where you want to save the model.
Loading the R torch model
To import the R torch model into the CounterfactualExplanations package, use the rtorch_model_loader() function. This function loads the model from the previously saved .pt file. Here is an example of how to load the R torch model:
julia
model_loaded = TaijaInteroperability.rtorch_model_loader("$(pwd())/docs/src/tutorials/miscellaneous/r_model.pt")
The rtorch_model_loader() function requires only one argument:
1. model_path: The path to the .pt file that contains the trained R torch model.
Wrapping the R torch model
Once the R torch model has been loaded into the package, wrap it inside the RTorchModel class. This step prepares the model to be used by the counterfactual generators. Here is an example:
julia
model_R = TaijaInteroperability.RTorchModel(model_loaded, counterfactual_data.likelihood)
Generating counterfactuals with the R torch model
Now that the R torch model has been wrapped inside the RTorchModel class, you can pass it into the counterfactual generators as you would with any other model.
Please note that RCall is not fully compatible with PythonCall. Therefore, it is advisable not to import both R torch and PyTorch models within the same Julia session. Additionally, it’s worth mentioning that the R torch integration is still untested in the CounterfactualExplanations package.
Owner
- Name: Taija
- Login: JuliaTrustworthyAI
- Kind: organization
- Location: Netherlands
- Repositories: 2
- Profile: https://github.com/JuliaTrustworthyAI
Home for repositories of the Taija (Trustworthy Artifical Intelligence in Julia) project.
Citation (CITATION.bib)
@misc{TaijaInteroperability.jl,
author = {Patrick Altmeyer},
title = {TaijaInteroperability.jl},
url = {https://github.com/JuliaTrustworthyAI/TaijaInteroperability.jl},
version = {v1.0.0-DEV},
year = {2023},
month = {10}
}
GitHub Events
Total
Last Year
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| pat-alt | a****t@g****m | 22 |
| kmariuszk | k****m@g****m | 19 |
| Rauno Arike | R****e@s****l | 2 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 9 months ago
All Time
- Total issues: 6
- Total pull requests: 10
- Average time to close issues: 3 days
- Average time to close pull requests: 5 days
- Total issue authors: 3
- Total pull request authors: 3
- Average comments per issue: 1.83
- Average comments per pull request: 0.3
- Merged pull requests: 6
- Bot issues: 0
- Bot pull requests: 4
Past Year
- Issues: 1
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 1
- Pull request authors: 0
- Average comments per issue: 1.0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- pat-alt (4)
- kmariuszk (1)
- JuliaTagBot (1)
Pull Request Authors
- kmariuszk (5)
- github-actions[bot] (4)
- RaunoArike (1)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- actions/checkout v3 composite
- codecov/codecov-action v3 composite
- julia-actions/cache v1 composite
- julia-actions/julia-buildpkg v1 composite
- julia-actions/julia-docdeploy v1 composite
- julia-actions/julia-processcoverage v1 composite
- julia-actions/julia-runtest v1 composite
- julia-actions/setup-julia v1 composite
- JuliaRegistries/TagBot v1 composite
- julia-actions/RegisterAction latest composite