Skip to content

Named Entity Recognition (NER) #12

@pymachado

Description

@pymachado
  1. Named Entity Recognition (NER) Module:

    • This module is designed to recognize and extract entities from text, such as user names and token symbols.
    • It leverages OpenAI's API to process text and identify these entities.
  2. Contracts Involved:

    • Alias Contract: This smart contract holds mappings of aliases to addresses. It helps in identifying and verifying users.
      • Example: AliasContract might map "Alice" to a specific blockchain address.
    • Token Information Contract: This smart contract holds the token symbols and names. It helps in identifying and verifying tokens.
      • Example: TokenInfoContract might map "ETH" to "Ethereum".
  3. Workflow:

    1. Entity Recognition: The NER module processes input text to identify entities such as user names and token symbols.
    2. API Calls: The system makes function calls to the smart contracts to retrieve the necessary information.
      • For a user alias, it queries the AliasContract to get the corresponding address.
      • For a token symbol, it queries the TokenInfoContract to get the full token name and additional details.
    3. Output: The system combines the information from the NER module and the smart contracts to identify and verify users and tokens accurately.

Example Workflow

  1. Input Text: "Alice sent 10 ETH"
  2. NER Module:
    • Identifies "Alice" as a user alias.
    • Identifies "ETH" as a token symbol.
  3. API Function Calls:
    • Calls AliasContract with "Alice" to get the blockchain address.
    • Calls TokenInfoContract with "ETH" to get the token details (e.g., "Ethereum").
  4. Output:
    • User: Alice -> Address: 0x123...
    • Token: ETH -> Ethereum

Smart Contract Interfaces

Here’s an example of what the smart contract interfaces might look like in Solidity:

// AliasContract.sol
pragma solidity ^0.8.0;

contract AliasContract {
    mapping(string => address) private aliases;

    // Add or update alias
    function setAlias(string memory alias, address addr) public {
        aliases[alias] = addr;
    }

    // Retrieve address by alias
    function getAddressByAlias(string memory alias) public view returns (address) {
        return aliases[alias];
    }
}

// TokenInfoContract.sol
pragma solidity ^0.8.0;

contract TokenInfoContract {
    struct TokenInfo {
        string name;
        string symbol;
    }

    mapping(string => TokenInfo) private tokens;

    // Add or update token information
    function setTokenInfo(string memory symbol, string memory name) public {
        tokens[symbol] = TokenInfo(name, symbol);
    }

    // Retrieve token info by symbol
    function getTokenInfoBySymbol(string memory symbol) public view returns (string memory) {
        return tokens[symbol].name;
    }
}

Integration with OpenAI API

In your backend system, you would integrate the OpenAI API with these contracts to process text input and make the necessary contract calls:

# Pseudo-code for integrating NER and smart contracts

def identify_entities(text):
    # Call OpenAI API to identify entities in the text
    entities = openai_ner_api(text)
    return entities

def get_user_address(alias):
    # Call AliasContract to get the address
    address = alias_contract.getAddressByAlias(alias)
    return address

def get_token_info(symbol):
    # Call TokenInfoContract to get the token information
    token_name = token_info_contract.getTokenInfoBySymbol(symbol)
    return token_name

# Example usage
text = "Alice sent 10 ETH"
entities = identify_entities(text)

user_address = get_user_address(entities['user_alias'])
token_info = get_token_info(entities['token_symbol'])

print(f"User: {entities['user_alias']} -> Address: {user_address}")
print(f"Token: {entities['token_symbol']} -> {token_info}")

This setup ensures that your system can accurately identify and verify users and tokens using the power of NER combined with the reliability of blockchain smart contracts.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions