class_docstr: Neural Attentional Rating Regression with Review-level Explanations
  
  Parameters
  ----------
  name: string, default: 'NARRE'
      The name of the recommender model.
  
  embedding_size: int, default: 100
      Word embedding size
  
  id_embedding_size: int, default: 32
      User/item review id embedding size
  
  n_factors: int, default: 32
      The dimension of the user/item's latent factors.
  
  attention_size: int, default: 16
      Attention size
  
  kernel_sizes: list, default: [3]
      List of kernel sizes of conv2d
  
  n_filters: int, default: 64
      Number of filters
  
  dropout_rate: float, default: 0.5
      Dropout rate of neural network dense layers
  
  max_text_length: int, default: 50
      Maximum number of tokens in a review instance
  
  max_num_review: int, default: 32
      Maximum number of reviews that you want to feed into training. By default, the model will be trained with 32 reviews.
  
  batch_size: int, default: 64
      Batch size
  
  max_iter: int, default: 10
      Max number of training epochs
  
  optimizer: string, optional, default: 'adam'
      Optimizer for training is either 'adam' or 'rmsprop'.
  
  learning_rate: float, optional, default: 0.001
      Initial value of learning rate for the optimizer.
  
  model_selection: str, optional, default: 'last'
      Model selection strategy is either 'best' or 'last'.
  
  user_based: boolean, optional, default: True
      Evaluation strategy for model selection, by default, it measures for every users and taking the average `user_based=True`. Set `user_based=False` if you want to measure per rating instead.
  
  trainable: boolean, optional, default: True
      When False, the model will not be re-trained, and input of pre-trained parameters are required.
  
  verbose: boolean, optional, default: True
      When True, running logs are displayed.
  
  init_params: dictionary, optional, default: None
      Initial parameters, pretrained_word_embeddings could be initialized here, e.g., init_params={'pretrained_word_embeddings': pretrained_word_embeddings}
  
  seed: int, optional, default: None
      Random seed for weight initialization.
      If specified, training will take longer because of single-thread (no parallelization).
  
  References
  ----------
  * Chen, C., Zhang, M., Liu, Y., & Ma, S. (2018, April). Neural attentional rating regression with review-level explanations. In Proceedings of the 2018 World Wide Web Conference (pp. 1583-1592).
class_docstr_tok: ["Neural","Attentional","Rating","Regression","with","Review-level","Explanations","Parameters","--","--","--","--","--","name",":","string",",","default",":","'NARRE'","The","name","of","the","recommender","model",".","embedding_size",":","int",",","default",":","100","Word","embedding","size","id_embedding_size",":","int",",","default",":","32","User\/item","review","id","embedding","size","n_factors",":","int",",","default",":","32","The","dimension","of","the","user\/item","'s","latent","factors",".","attention_size",":","int",",","default",":","16","Attention","size","kernel_sizes",":","list",",","default",":","[","3","]","List","of","kernel","sizes","of","conv2d","n_filters",":","int",",","default",":","64","Number","of","filters","dropout_rate",":","float",",","default",":","0.5","Dropout","rate","of","neural","network","dense","layers","max_text_length",":","int",",","default",":","50","Maximum","number","of","tokens","in","a","review","instance","max_num_review",":","int",",","default",":","32","Maximum","number","of","reviews","that","you","want","to","feed","into","training",".","By","default",",","the","model","will","be","trained","with","32","reviews",".","batch_size",":","int",",","default",":","64","Batch","size","max_iter",":","int",",","default",":","10","Max","number","of","training","epochs","optimizer",":","string",",","optional",",","default",":","'adam'","Optimizer","for","training","is","either","'adam","'","or","'rmsprop","'",".","learning_rate",":","float",",","optional",",","default",":","0.001","Initial","value","of","learning","rate","for","the","optimizer",".","model_selection",":","str",",","optional",",","default",":","'last'","Model","selection","strategy","is","either","'best","'","or","'last","'",".","user_based",":","boolean",",","optional",",","default",":","True","Evaluation","strategy","for","model","selection",",","by","default",",","it","measures","for","every","users","and","taking","the","average","`","user_based=True","`",".","Set","`","user_based=False","`","if","you","want","to","measure","per","rating","instead",".","trainable",":","boolean",",","optional",",","default",":","True","When","False",",","the","model","will","not","be","re-trained",",","and","input","of","pre-trained","parameters","are","required",".","verbose",":","boolean",",","optional",",","default",":","True","When","True",",","running","logs","are","displayed",".","init_params",":","dictionary",",","optional",",","default",":","None","Initial","parameters",",","pretrained_word_embeddings","could","be","initialized","here",",","e.g.",",","init_params=","{","'pretrained_word_embeddings","'",":","pretrained_word_embeddings","}","seed",":","int",",","optional",",","default",":","None","Random","seed","for","weight","initialization",".","If","specified",",","training","will","take","longer","because","of","single-thread","(","no","parallelization",")",".","References","--","--","--","--","--","*","Chen",",","C.",",","Zhang",",","M.",",","Liu",",","Y.",",","&","Ma",",","S.","(","2018",",","April",")",".","Neural","attentional","rating","regression","with","review-level","explanations",".","In","Proceedings","of","the","2018","World","Wide","Web","Conference","(","pp",".","1583-1592",")","."]
docstr: Load a recommender model from the filesystem.
  
  Parameters
  ----------
  model_path: str, required
      Path to a file or directory where the model is stored. If a directory is
      provided, the latest model will be loaded.
  
  trainable: boolean, optional, default: False
      Set it to True if you would like to finetune the model. By default,
      the model parameters are assumed to be fixed after being loaded.
  
  Returns
  -------
  self : object
docstr_tok: ["Load","a","recommender","model","from","the","filesystem",".","Parameters","--","--","--","--","--","model_path",":","str",",","required","Path","to","a","file","or","directory","where","the","model","is","stored",".","If","a","directory","is","provided",",","the","latest","model","will","be","loaded",".","trainable",":","boolean",",","optional",",","default",":","False","Set","it","to","True","if","you","would","like","to","finetune","the","model",".","By","default",",","the","model","parameters","are","assumed","to","be","fixed","after","being","loaded",".","Returns","--","--","--","-","self",":","object"]
code: def load(model_path, trainable=False):
      """Load a recommender model from the filesystem.
  
      Parameters
      ----------
      model_path: str, required
          Path to a file or directory where the model is stored. If a directory is
          provided, the latest model will be loaded.
  
      trainable: boolean, optional, default: False
          Set it to True if you would like to finetune the model. By default,
          the model parameters are assumed to be fixed after being loaded.
  
      Returns
      -------
      self : object
      """
      import tensorflow as tf
      from tensorflow import keras
      import absl.logging
  
      absl.logging.set_verbosity(absl.logging.ERROR)
  
      model = Recommender.load(model_path, trainable)
      model.model.graph = keras.models.load_model(
          model.load_from.replace(".pkl", ".cpt"), compile=False
      )
      if model.optimizer == "rmsprop":
          model._optimizer = keras.optimizers.RMSprop(
              learning_rate=model.learning_rate
          )
      else:
          model._optimizer = keras.optimizers.Adam(
              learning_rate=model.learning_rate
          )
      zero_grads = [
          tf.zeros_like(w)
          for w in model.model.graph.trainable_variables
      ]
      model._optimizer.apply_gradients(
          zip(zero_grads, model.model.graph.trainable_variables)
      )
      with open(model.load_from.replace(".pkl", ".opt"), "rb") as f:
          optimizer_weights = pickle.load(f)
      model._optimizer.set_weights(optimizer_weights)
  
      return model
  
file_path: cornac/cornac/models/narre/recom_narre.py
imports: import os
  import pickle
  from tqdm.auto import trange
  import numpy
  from ..recommender import Recommender
  from ..recommender import ANNMixin, MEASURE_DOT
  from ...exception import ScoreException
label_desc: Use image node_id 5 for calling the NARRE obj's underlying member method code with example usage: obj.load(model_path, trainable) and returns: model