mikeizbicki / cmc-csci181-deeplearning

deep learning course materials
15 stars 6 forks source link

Project part 1 visualization problems #24

Open mikeizbicki opened 4 years ago

mikeizbicki commented 4 years ago

When I'm running my code, the output I get looks like this: line0000 word

Any idea what I'm doing wrong? Side note: the pattern of starting dark green and getting slightly lighter as it goes on is true for the character-by-character analysis as well

Originally posted by @jwsbrennan in https://github.com/mikeizbicki/cmc-csci181/issues/22#issuecomment-615332150

mikeizbicki commented 4 years ago

@jwsbrennan There's two possibilities: either you're not creating your scores vector properly (most likely), or you're not calling the line2img function correctly.

You should print out the actual values of your scores vector to inspect what they're equal to. Based on the fact that they get lighter as the index moves to the right, my guess is that somehow the formula you are using to calculate them contains the index in it in a way that it shouldn't be.

keweizhou1999 commented 4 years ago

I'm seeing a similar issue with the visualization, except that even the blanks are all colored differently. I've attached my code below, and I'm wondering if you can give me a hint on how to debug this code. Thank you!

line = line.strip()
    if args.case_insensitive:
        line = line.lower()
    input_tensor = str_to_tensor([line],args.input_length)          # size = [x, 1, 76]
    output_class,output_nextchars = model(input_tensor)
    probs = softmax(output_class)
    scores = torch.zeros([len(line)])
    print("input_tensor: ", input_tensor)

    for i in range(len(line)):
            new_tensor = input_tensor
            new_tensor[i+1,0] = torch.zeros([len(vocabulary)])          # +1 to exclude the starting char
            new_output,new_nextchars = model(new_tensor)
            new_probs = softmax(new_output)
            scores[i] = torch.dist(probs, new_probs)

    line2img(line,scores,filename)

line0007 char

mikeizbicki commented 4 years ago

@keweizhou1999 The first thing I notice is that torch.dist does not calculate the l2 form between two vectors, so that could be messing up your results.

keweizhou1999 commented 4 years ago

I've tried using torch.dist(probs, new_probs, 2) and torch.norm(), but it's still producing some sort of all green figure line0017 char

mikeizbicki commented 4 years ago

For anyone else who has this same problem, we looked at it in office hours and realized that the problem was that line

            new_tensor = input_tensor

does not create a copy of the tensor, and you need to explicitly call the clone function.