Some understand rasa [summary] [python] learning process

A, pickle usage, and why should pickle

  Use pickle it is directly a function of serialization and de-serialization. It can be simply understood as a format to save txt and encrypted, then decrypted when needed and used to obtain the original data sequence pattern.

(1) pickle function of usage:

  Generally the most common is pickle.dump () and pickle.load () function. Corresponds to the sequence and deserialization process, can be understood as an archive (preserve the original data structure) and read files (the saved data file returns to the original structure)

Two types of functions when using all need to open the txt file before proceeding. Import pickle package before use.

①pickle.dump () Example:

dictionary_obj = r'dictionary_obj.txt'
with open(dictionary_obj,'wb') as f:     
  pickle.dump(dictionary,f)

②pickle.load () Example:

vector_path = "F:/pyProject/NativeNLP/data/dictionary_obj.txt"
f = open (vector_path,"rb")
vector_dict = pickle.load (f)
f.close()
Wherein the WB, is represented rb Open (opened in binary format writable, readable binary format open, there are other w, r, w + mode, etc.), as a function of pickle stored in binary files saved, We need to pay attention.

(2) the use of pickle function of significance:

  Easy storage. Process sequence is from the text information converted to the binary data stream, and deserializing the data is converted into the original stream. Binary data more convenient for storing data.

  In addition, by means of pickle into the storage function may be strings, lists, dictionaries and other data, the data having the sequence information is saved and stored.

 

Action II python class and instance attributes, method

  From personal understanding, the class is like a framework, there are a variety of properties and rules.

  Students who take this class, he represents an abstract concept, we can be filled as needed. Such as student gender, age, class these are the "student" attribute of this class, and the methods that we use this type of channel.

For example, you want to know the student's name, in real life we ​​need to query, and the query process, in the class as get_name function is achieved by means of the method.

  Class and attribute will have a corresponding function, when called with "self." Can call, a plurality of objects of the same class sharing methods and properties, but not between different instances of the shared objects.

  Examples of this significance is "student" of the actual class, to fill. For example, students Li, male, 18 years old, and so is our class 3 to fill in the instantiation may not be assigned because there is a default value.

  With class and instance properties, methods, allows us to better sort out the logic, post code maintenance.


Three, rasa method of adding components

  After a preliminary understanding of the framework rasa, understand the meaning of each module. Rasa process operation is carried out step by step in accordance with a pipeline, the pipeline in a predetermined order of execution of the components and the number of sets the initial value of the class variable.

In each assembly has its own classes and methods, and marked and their operation portion provided required.

  I want to add a new component, follow these steps:

① create documents in the folder corresponding classification: such as classification, marking, and other data folder selected based on practical component classification.

② registry files rasa framework to register: Registration is divided into two parts

  • Add the class name in the new assembly in component_classes
  • Add the folder directory names from all levels. Component name import the new component class name

③ in the construction of new pipeline configuration file or modify the original document pipeline

  •  Order pipeline will be prepared in accordance with the actual implementation, the first to write is first executed. For example word should be in before the term vectors to change and so on.

④ test


Four, python dictionary use

  Dictionary format: D = { key1 : VALUE1 , key2 : value2 }

① access dictionary: dict [key1 ]

If there is no such key values ​​being given: KeyError: 'key1'

② modify the dictionary entry:

  dict [ 'key1 ' ] = . 8 # Update   dict [ 'key3 ' ] = " value3 " # Add

③ delete dictionary entry:

  del dict [ key1 ] # delete key is 'key1' entry   dict . the Clear ( ) # Empty dictionary all entries   del dict # Delete dictionary  
     
         

④ matches:

dict.has_key (key)
if the key is in the dictionary dict returns true, otherwise returns false

dict.get (key, default = None)
Returns the specified key, if the default return value not in the dictionary (the most commonly used search key value and returns the corresponding value of the value)

E.g:

= TEMP self.vector_dict [token.text] is the return value is vector_dict dictionary key value corresponding value token.text

Guess you like

Origin www.cnblogs.com/lemonbo77/p/11700086.html