Havina
Havina is a Python library that can generate knowledge graphs triplets from an input text. Its implementation is based on the paper "Language models are open knowledge graphs" with some tweaks to improve performance. Most notably, instead of summing the attention scores of each word in a relation, I am calculating their average.
The reasoning behind this change is that a simple sum of scores favors longer relations even if the extra words do not carry any relevant meaning.
Havina can be used to evaluate the language comprehension of AI models or as a tool to extract triplets from text and build knowledge graphs.
How to use it
Run pip install havina to install the library. Then, after importing the GraphGenerator class
from havina, simply call the object with the sentence to evaluate and an optional number of workers.
Each worker will span a different process and the algorithm will split the work between them.
from havina import GraphGenerator
text = 'John Lennon is a famous singer.'
generator = GraphGenerator(
top_k=4,
contiguous_token=False
)
triplets = generator(text, workers=1)
print(triplets)
The code above will print the following:
[
HeadTailRelations(
head=Entity(text='john lennon', wikidata_id=None),
tail=Entity(text='a famous singer', wikidata_id=None),
relations=['be'])
]
The returned type is a list of HeadTailReations objects, each of which contains
the head and tail entities and the possible relations between them. Relations are
Python strings.
Metadata
Release files for Havina 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| havina-0.1.3.tar.gz | 158.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| havina-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 175.9 kB
Release files / havina-0.1.3.tar.gz
| Download URL | havina-0.1.3.tar.gz |
|---|---|
| Size | 158.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
590b8d91eee3f1ed69d12b9d4372b3c2d42117b455b46218a250b0a7ab71e7ff
|
|
BLAKE2b-256 checksum How to use checksums |
8707bf3156b3a9a3d77f23a56c761a626f6b892ae6b47e1c2a499f46c19e6204
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / havina-0.1.3-py3-none-any.whl
| Download URL | havina-0.1.3-py3-none-any.whl |
|---|---|
| Size | 17.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
54dfdcec37631a7574658762d9cabbd9a17c9ad9cd96868acb1d9520d5495a51
|
|
BLAKE2b-256 checksum How to use checksums |
9f6ce3bad1dd2e280014c453211f2194c516ea0f5aaccda316f5a6314dfa7ff9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|