Modeling gossip Series 75 intelligent agent

explain

The problem of not having a clue in an hour must not be the main problem

I remember when I was in school, I learned the main contradiction and the secondary contradiction. The secondary contradiction may gradually become the main contradiction. I feel it's a secondary contradiction to remember something before. Now I feel that I forget it while I remember it.

In the past, it was more about the realizability of various functions and algorithms. Now there are too many thoughts to grasp. In addition, I have always wanted to assist in various things through AI, so I want to start doing some practice.

AI is a tool to help people save labor and time

content

Let's start with a simple prototype using local storage. The simple function of this prototype is to record something and then provide query.

import pickle
# Store results
def to_pickle(data, file_name,  path='./'):
	output = open(path+file_name+'.pkl', 'wb')
	pickle.dump(data, output)
	output.close()
	print('data save to pickle: ', path+file_name+'.pkl')

# Load results
def from_pickle(file_name, path='./'):
	output = open(path+file_name+'.pkl', 'rb')
	data = pickle.load(output)
	output.close()
	return data

from datetime import datetime
str_format = '%Y-%m-%d %H:%M:%S'


import time 

class AndyAgent:
    def __init__(self, name , fpath = './'):
        self.name = name
        self.fpath = fpath
        try:
            self.Data = from_pickle(name,fpath)
        except:
            print('New agent,No historical data was read')
            # Data is a dictionary, ready to dock with mongo
            self.Data =  {}
    
    # Original record
    def rec(self, sentence):
        new_data = {}
        new_data['content'] = sentence
        new_data['ts'] = time.time()
        # Use microsecond timestamps as the
        self.Data[int(new_data['ts'] *1e6)] = new_data
        # Then store
        to_pickle(self.Data, self.name,self.fpath)
        
    # query
    def query(self):
        self.question = input('Please enter keyword:')
        self.answer()
        
    # answer
    def answer(self):
        self.answer_list = []
        for k in self.Data.keys():
            rec = self.Data[k]
            content = rec['content']
            
            t_struct =time.localtime(rec['ts'])
            ts =time.strftime(str_format,t_struct)
            rec_tuple = content, ts
            self.answer_list.append(rec_tuple)
            
        print('find%s Records' % len(self.answer_list))
        print(self.answer_list)
    # Entity recognition
    # Find the time, place, people and company
    def analysis(self):
        pass
    
    # Record a relationship
    def rec_a_link(self, from_node, to_node, link_type, attr_dict):
        pass
    # Infer a relationship
    def refer_a_link(self, content):
        pass 
    
    # Notification: SMS or email
    def inform_msg(self, to_list, template_id, content):
        pass
---
# aoa = Agent of Andy
aoa = AndyAgent('andy')

aoa.Data
{1635001088509037: {'content': 'I'm going to the airport tomorrow', 'ts': 1635001088.5090373},
 1635001118614797: {'content': 'I'm going to the airport tomorrow', 'ts': 1635001118.6147974}}
aoa.query()
Please enter keyword: Airport
 2 records found
[('I'm going to the airport tomorrow', '2021-10-23 22:58:08'), ('I'm going to the airport tomorrow', '2021-10-23 22:58:38')]

Some thoughts on Design

I hope the Agent can realize these functions:

  • 1 record problems (data) and analyze them
  • 2 translate and replace manually executed code
  • 3 answer questions

Data organization:

  • Organize (nodes) and relationships as a graph

Application of machine learning:

  • 1 use natural language to analyze characters.
  • 2 create algorithms for knowledge discovery and knowledge inference
  • 3 strengthen learning methods and improve their own services

Architecture support:

  • 1. You can send text messages and emails
  • 2. Use the scheduler to run persistently, and give reminders according to time
  • 3. Persistence of Mongo library. Data in dictionary format can be easily mapped to the database.
  • 4 neo4j for relational storage and query. It can be stored first in the form of a convertible table, and then it can be simply mapped.

Posted on Sat, 23 Oct 2021 11:36:46 -0400 by Louis11