Skip to main content

ConceptNet and embeddings with a local DB and API.

Project description

Local ConceptNet

ConceptNet and fastText embeddings with a local DB and API. English only.

Example Usage

Import:

import conceptnet_local as cnl

Concept Details

List of all concept IDs:

all_concept_ids = cnl.get_all_concept_ids()

All edges connecting to a concept:

edges = cnl.get_all_edges(cn_id="/c/en/example")

Relatedess between two concepts according to fastText embeddings:

relatedness = cnl.get_relatedness("/c/en/example", "/c/en/test")

Lowest-Cost Paths

Get a variant of A* by specifying cost and heuristic weights:

from conceptnet_local import get_a_star_variant, CostFunction, HeuristicFunction

CustomAStar = get_a_star_variant(
    cost_weights={
        CostFunction.EDGE_COUNT: 2.,
        CostFunction.SIMILARITY_DIFFERENCE: 1.,
    },
    heuristic_weights={
        HeuristicFunction.SIMILARITY_TO_GOAL: 1.,
    }
)

or create a fully custom variant of A*:

from conceptnet_local import AStar, Concept, Relation

class CustomAStar(AStar):
    def get_cost(self, source: Concept, target: Concept, relation: Relation, goal: Concept) -> float:
        ...

    def get_heuristic(self, current: Concept, goal: Concept) -> float:
        ...

Get the lowest-cost path:

custom_a_star = CustomAStar()
path = custom_a_star.compute_path(input_concept="/c/en/example", output_concept="/c/en/test", print_time=True)

print(cnl.format_path(path=path))

Custom Queries

Get a reference to the DB:

connection, cursor = cnl.setup_sqlite_db()

Execute queries, e.g.:

partial_id = "examp"
statement = cursor.execute("SELECT embedding FROM embeddings WHERE concept_id LIKE '%?%'", (partial_id,))
result = statement.fetchall()

Close DB connection:

cnl.close_sqlite_db(db_connection=connection)

Database

The DB can be set up by navigating to the db_setup directory and following the instructions in the notebook there.

Version History

1.0

  • release 🎉

0.9

  • concept extraction from text
  • concept degree retrieval

0.8

  • concepts table
  • retrieval of similar concepts
  • concept existence check

0.7

  • separate utils file
  • link label formatting
  • natural-language path formatting

0.6

  • no more FastText model built in
  • embedding computation method optional in relatedness method
  • optimized embedding retrieval from DB

0.5

  • custom initialization method in A*

0.4

  • FastText embeddings for arbitrary text

0.3

  • retrieval of all concept IDs

0.2

  • FastText embeddings

0.1

  • reading links and embeddings from DB
  • custom A* with configurable variants
  • greedy version of Yen's algorithm

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

conceptnet_local-1.0.0.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

conceptnet_local-1.0.0-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file conceptnet_local-1.0.0.tar.gz.

File metadata

  • Download URL: conceptnet_local-1.0.0.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for conceptnet_local-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6e059a4a0da3c5b81deef0ec5a59d568f2ecfe8b3b5f26cd2cd95b6af29f3964
MD5 3effdc8f32a9df39988dac6a7cacb5e2
BLAKE2b-256 e5a247dd0a3de45b2cd402a2706284b8a2191dd277cd4542721853f90852aa92

See more details on using hashes here.

File details

Details for the file conceptnet_local-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for conceptnet_local-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 207b2ae905868ada8955901d66997e70779f70222fc727fb131408bb4a413911
MD5 6e18430ae0479fbbeb09be5f74bca05e
BLAKE2b-256 2772e54c286d12ae237af1c21d3ad6725a9ae9becfa2f0b6002bc2a397befb0c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page