kandi background
Explore Kits

gmf | Go Media Framework | Media library

 by   3d0c Go Version: Current License: MIT

 by   3d0c Go Version: Current License: MIT

kandi X-RAY | gmf Summary

gmf is a Go library typically used in Media, Framework applications. gmf has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.
Go Media Framework
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • gmf has a medium active ecosystem.
  • It has 816 star(s) with 164 fork(s). There are 30 watchers for this library.
  • It had no major release in the last 6 months.
  • There are 45 open issues and 33 have been closed. On average issues are closed in 196 days. There are 1 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of gmf is current.
gmf Support
Best in #Media
Average in #Media
gmf Support
Best in #Media
Average in #Media

quality kandi Quality

  • gmf has 0 bugs and 0 code smells.
gmf Quality
Best in #Media
Average in #Media
gmf Quality
Best in #Media
Average in #Media

securitySecurity

  • gmf has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • gmf code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
gmf Security
Best in #Media
Average in #Media
gmf Security
Best in #Media
Average in #Media

license License

  • gmf is licensed under the MIT License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
gmf License
Best in #Media
Average in #Media
gmf License
Best in #Media
Average in #Media

buildReuse

  • gmf releases are not available. You will need to build from source code and install.
  • Installation instructions are not available. Examples and code snippets are available.
  • It has 7442 lines of code, 593 functions and 57 files.
  • It has high code complexity. Code complexity directly impacts maintainability of the code.
gmf Reuse
Best in #Media
Average in #Media
gmf Reuse
Best in #Media
Average in #Media
Top functions reviewed by kandi - BETA

kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here

Get all kandi verified functions for this library.

Get all kandi verified functions for this library.

gmf Key Features

Go Media Framework

gmf Examples and Code Snippets

Community Discussions

Trending Discussions on gmf
  • No attribute 'compile', how can I modify the class, so that it works?
  • Cusotm markers in mapbox gl js does not work?
  • Cannot display a popup on hover over a route in mapbox
  • Display textBox.Text in Windows Form with "idx" iterating through for loop
Trending Discussions on gmf

QUESTION

No attribute 'compile', how can I modify the class, so that it works?

Asked 2020-Oct-20 at 21:43

The neuMF class is not a Keras's class and therefore it doesn't provide any compile method. I would better use keras.Model instead of nn.Blocks.

Unfortunately, I do not really understand what nn.Blocks is and how I could replace it in the class. How should I modfy my code, so that it works with keras.Model and can use the Keras method?

Here is my code:

from d2l import mxnet as d2l
from mxnet import autograd, gluon, np, npx
from mxnet.gluon import nn
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers


    class NeuMF(nn.Block):
        def init(self, num_factors, num_users, num_items, nums_hiddens,
                     kwargs):
            super(NeuMF, self).init(kwargs)
            self.P = nn.Embedding(num_users, num_factors)
            self.Q = nn.Embedding(num_items, num_factors)
            self.U = nn.Embedding(num_users, num_factors)
            self.V = nn.Embedding(num_items, num_factors)
            self.mlp = nn.Sequential()
            for num_hiddens in nums_hiddens:
                self.mlp.add(nn.Dense(num_hiddens, activation='relu',
                                      use_bias=True))
            self.prediction_layer = nn.Dense(1, activation='sigmoid', use_bias=False)
    
        def forward(self, user_id, item_id):
            p_mf = self.P(user_id)
            q_mf = self.Q(item_id)
            gmf = p_mf * q_mf
            p_mlp = self.U(user_id)
            q_mlp = self.V(item_id)
            mlp = self.mlp(np.concatenate([p_mlp, q_mlp], axis=1))
            con_res = np.concatenate([gmf, mlp], axis=1)
            return self.prediction_layer(con_res)
    
    
    hidden = [5,5,5]
    
    model = NeuMF(5, num_users, num_items, hidden)
    model.compile(
         #loss=tf.keras.losses.BinaryCrossentropy(),
        loss=tf.keras.losses.MeanSquaredError(),
        optimizer=keras.optimizers.Adam(lr=0.001)
    )

And I get the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-21-5979072369bd> in <module>()
      2 
      3 model = NeuMF(5, num_users, num_items, hidden)
----> 4 model.compile(
      5      #loss=tf.keras.losses.BinaryCrossentropy(),
      6     loss=tf.keras.losses.MeanSquaredError(),

AttributeError: 'NeuMF' object has no attribute 'compile'

Thank you a lot in advance!

Edit:

I replaced nn to layers

class NeuMF(keras.Model):
    def __init__(self, num_factors, num_users, num_items, nums_hiddens,
                 **kwargs):
        super(NeuMF, self).__init__(**kwargs)
        self.P = layers.Embedding(num_users, num_factors)
        self.Q = layers.Embedding(num_items, num_factors)
        self.U = layers.Embedding(num_users, num_factors)
        self.V = layers.Embedding(num_items, num_factors)
        self.mlp = layers.Sequential()
        for num_hiddens in nums_hiddens:
            self.mlp.add(layers.Dense(num_hiddens, activation='relu',
                                  use_bias=True))
        self.prediction_layer = layers.Dense(1, activation='sigmoid', use_bias=False)

    def forward(self, user_id, item_id):
        p_mf = self.P(user_id)
        q_mf = self.Q(item_id)
        gmf = p_mf * q_mf
        p_mlp = self.U(user_id)
        q_mlp = self.V(item_id)
        mlp = self.mlp(np.concatenate([p_mlp, q_mlp], axis=1))
        con_res = np.concatenate([gmf, mlp], axis=1)
        return self.prediction_layer(con_res)

Then I got an new error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-26-7e09b0f80300> in <module>()
      1 hidden = [1,1,1]
      2 
----> 3 model = NeuMF(1, num_users, num_items, hidden)
      4 model.compile(
      5      #loss=tf.keras.losses.BinaryCrossentropy(),

1 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/layers/embeddings.py in __init__(self, input_dim, output_dim, embeddings_initializer, embeddings_regularizer, activity_regularizer, embeddings_constraint, mask_zero, input_length, **kwargs)
    102       else:
    103         kwargs['input_shape'] = (None,)
--> 104     if input_dim <= 0 or output_dim <= 0:
    105       raise ValueError('Both `input_dim` and `output_dim` should be positive, '
    106                        'found input_dim {} and output_dim {}'.format(

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

ANSWER

Answered 2020-Oct-20 at 21:43

After already quite some discussion in the comments, there are still several problems with your code and clarification needed from your side:

  1. subclasses of keras.Model should implement the __call__ method, but not a forward method.
  2. you can't just build numpy-operations like np.concatenate inside your model, always use keras-layers like tf.keras.layers.Concatenate.
  3. as already commented, the error you've posted most likely comes from num_factors, num_users, num_items not being integer, though I can only guess here, since you did not provide those to us.
  4. also, I can currently only guess what you are trying to achieve, since this is not at all clear from what you posted.

Let us approach the issues in a different way. The following code snippet runs without error and might be a good starting point for you:

import tensorflow as tf

class NeuMF(tf.keras.Model):
    def __init__(self, num_factors, num_users, num_items, nums_hiddens,
                 **kwargs):
        super(NeuMF, self).__init__(**kwargs)
        self.P = tf.keras.layers.Embedding(num_users, num_factors)
        self.Q = tf.keras.layers.Embedding(num_items, num_factors)
        self.U = tf.keras.layers.Embedding(num_users, num_factors)
        self.V = tf.keras.layers.Embedding(num_items, num_factors)
        self.mlp = tf.keras.Sequential()
        for num_hiddens in nums_hiddens:
            self.mlp.add(
                tf.keras.layers.Dense(
                    num_hiddens,
                    activation='relu',
                    use_bias=True
                    )
                )
        self.prediction_layer = tf.keras.layers.Dense(1, activation='sigmoid', use_bias=False)

    def __call__(self, inputs):
        x  = self.P(inputs[0])
        x1 = self.Q(inputs[1])
        x  = tf.keras.layers.Multiply()([x,x1])

        y = self.U(inputs[0])
        y1 = self.V(inputs[1])
        y = tf.keras.layers.Concatenate()([y,y1])
        y = self.mlp(y)
        x = tf.keras.layers.Concatenate()([x,y])
        return self.prediction_layer(x)

if __name__ == '__main__':
    #replace these with values of your choice:
    num_factors = 2
    num_users   = 3
    num_items   = 4 
    nums_hidden = [5,5,5]

    model = NeuMF(num_users, num_items, num_items, nums_hidden)
    model.compile(
        loss = tf.keras.losses.MeanSquaredError(),
        optimizer = tf.keras.optimizers.Adam(lr=0.001)
        )

Source https://stackoverflow.com/questions/64440377

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install gmf

You can download it from GitHub.

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

Find more information at:

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 650 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases
Explore Kits

Save this library and start creating your kit

Clone
  • https://github.com/3d0c/gmf.git

  • gh repo clone 3d0c/gmf

  • git@github.com:3d0c/gmf.git

Share this Page

share link

See Similar Libraries in

Reuse Pre-built Kits with gmf
Consider Popular Media Libraries
Try Top Libraries by 3d0c
Compare Media Libraries with Highest Support
Compare Media Libraries with Highest Quality
Compare Media Libraries with Highest Security
Compare Media Libraries with Permissive License
Compare Media Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 650 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases
Explore Kits

Save this library and start creating your kit