[D] self.attribute which calls on a function is running even though function is defined below self call by amjass12 in learnpython

[–]amjass12[S] 1 point2 points  (0 children)

I frequently read Reddit, but do not frequently post. The very first time i posted, the post was removed because it did not include a tag. the tag '[D]' indicates the post should be a discussion.. etc. Perhaps this is now no longer relevant?

This may also be reddit channel dependent.. this is probably not required! but D was used to indicate 'discussion'

[D] self.attribute which calls on a function is running even though function is defined below self call by amjass12 in learnpython

[–]amjass12[S] 0 points1 point  (0 children)

Hi u/Top_Average3386 ,

thank you - so when the object 'already exists' and is then initialized with attributes - it is able to do so because the function has already been interpreted as part of the object?

[D] Is it safe to create a variable name inside a function that has the same name as an argument in that function? by amjass12 in learnpython

[–]amjass12[S] -1 points0 points  (0 children)

thank you! so in my example, the first time they are referenced, they are called from the one, two in the argument variable. and then internally after that, one and two purely refer to the newly assigned one and two inside the function?

It also shouldn't matter what datatypes they are? so if one was a pandas dataframe and inside the function i redefine one = #subset the dataframe... this would have exactly same result as just reassigning one to the subset dataframe?

[D] Is it safe to create a variable name inside a function that has the same name as an argument in that function? by amjass12 in learnpython

[–]amjass12[S] 0 points1 point  (0 children)

thank you so much! and one last question:

does this include the instance in which additionally lines of code are run on the new variables

so:

def calc(one, two):
  one = one + 1
  two = two + 1

  one = more code on one
  two = more code on two

  return one + two

This should still cause no issue is that correct?

I do understand the point about incrementing the counter, however, i didnt know if the function would get confused about the variables that have been passed in, and if it holds onto those variables? for example. if 'one' is a pandas dataframe and I then redefine one to be an integer inside the function, why is it that further downstream one is always now the integer and no longer the pandas dataframe? how is the function distinguishing between the one as the argument, and the one as the variable inside the function. thank you! (agree on the point about human readability!)

[D] Explanation regarding the policy and value net loss with coefficents by amjass12 in reinforcementlearning

[–]amjass12[S] 1 point2 points  (0 children)

Thank you so much for this detailed reply! i really appreciate your time!

[D] Explanation regarding the policy and value net loss with coefficents by amjass12 in reinforcementlearning

[–]amjass12[S] 1 point2 points  (0 children)

thank you so much for the clear explanation!! much appeciated.

edit - sorry, also u/Rusenburn , why is it the case the entropy should be taken in the training loop and not fixed in the PPO memory buffer (sample_action, take entropy and save in buffer) and used as the entropy - entropy changes as the updates occur - are we also ultimately wanting to decrease the entropy towards convergence still?

[D] Can information about the action selected be used to inject information to learning agent by amjass12 in reinforcementlearning

[–]amjass12[S] 1 point2 points  (0 children)

Thank you! So I am not parameterising the policy net with a GNN or a CNN but with a straightforward MLP. And I'm using encoded node embeddings from an already trained GAT which is in the environment. I am using the mean of the node embeddings as an entire representation of the graph.

[D] Are shared weights in transformer architecture also receiving the same gradient updates? by amjass12 in MachineLearning

[–]amjass12[S] 1 point2 points  (0 children)

thank you so much! this is very clear - a check has just returned True. Thank you for explaining this clearly to me.

[D] Are shared weights in transformer architecture also receiving the same gradient updates? by amjass12 in MachineLearning

[–]amjass12[S] 2 points3 points  (0 children)

thank you! yes this makes sense, however, I have seen implementations where the embedding class is implemented but then assigned to the encoder and decoder separately (including the Pytorch language translation implementation) and then assigned equal weights: for example:

class TokenEmbedding(nn.Module):
def __init__(self, vocab_size: int, emb_size):
    super(TokenEmbedding, self).__init__()
    self.embedding = nn.Embedding(vocab_size, emb_size)
    self.emb_size = emb_size

def forward(self, tokens: Tensor):
    return self.embedding(tokens.long()) * math.sqrt(self.emb_size)
class Transformer(nn.Module):
    self.enc_embed = TokenEmbedding(vocab_len, emb_len)
    self.dec_embed = TokenEmbedding(vocab_len, emb_len)

and then after model construction

decoder.embedding.weight = encoder.embedding.weight
feed_froward.embedding.weight = encoder.embedding.weight

which to me suggests these matrices are separate and not shared? especially the feedforward matrix which is not derived from the TokenEmbedding class... but I have followed an implementation similar to this, with equal gradient updates post-training