Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
The reason why you don't see `OK 1 1` is that the `negative` list generated from the query parameters contains a single string which is a concatenation of the title and authors, while the `titles` list only contains individual titles. Therefore, the list comprehension that generates `keep_no` does not find any matching titles in the `negative` list and returns an empty list. To fix this, you can split the `negative` string by the `Title:` keyword before splitting it by the `##` separator. Here is the updated code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '').split("##") negative = [x.split("##") for x in request.args.get('negative', '').split("Title:")] negative = [y[0] for x in negative for y in x if y] keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
I asked a question about why some code was incorrect. The answer is "because the input contains an extra curly brace }". Does this student answer say that? The reason why you don't see `OK 1 1` is that the `negative` list generated from the query parameters contains a single string which is a concatenation of the title and authors, while the `titles` list only contains individual titles. Therefore, the list comprehension that generates `keep_no` does not find any matching titles in the `negative` list and returns an empty list. To fix this, you can split the `negative` string by the `Title:` keyword before splitting it by the `##` separator. Here is the updated code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '').split("##") negative = [x.split("##") for x in request.args.get('negative', '').split("Title:")] negative = [y[0] for x in negative for y in x if y] keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
The student fails. The provided answer does not address the issue of an extra curly brace `}` in the input, as mentioned in the question. Instead, it explains a different problem related to how the `negative` list is generated and processed, and it offers a solution to that problem.
Testing if the previous output contains the string student passes
: False
Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
The reason you're not getting `OK 1 1` is that the negative titles are not being found in the `titles` list. In your code, you're splitting the `positive` and `negative` arguments by the `"##"` delimiter, but the input data doesn't contain this delimiter. Instead, the titles and authors are separated by a newline character `"\n"`. To fix this, you can modify the splitting lines as follows:
1 2 | positive = request.args.get('positive', '').split("\n") negative = request.args.get('negative', '').split("\n") |
I asked a question about why some code was incorrect. The answer is "because the input contains an extra curly brace }". Does this student answer say that? The reason you're not getting `OK 1 1` is that the negative titles are not being found in the `titles` list. In your code, you're splitting the `positive` and `negative` arguments by the `"##"` delimiter, but the input data doesn't contain this delimiter. Instead, the titles and authors are separated by a newline character `"\n"`. To fix this, you can modify the splitting lines as follows:
1 2 | positive = request.args.get('positive', '').split("\n") negative = request.args.get('negative', '').split("\n") |
The student fails.
Testing if the previous output contains the string student passes
: False
Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
The issue lies in the fact that the `negative` list of titles is not present in the `titles` list. The code is searching for exact matches of the titles in the `negative` list within the `titles` list, but it is not finding any matches. Therefore, the length of `set1_no` remains 0. To fix this problem, make sure that the titles in the `negative` list are present in the `titles` list, or modify the code to properly handle cases where the titles are not found. Here is one possible change to the code:
1 2 3 | # Add a check to see if any titles were found in the negative list if not set1_no: print("No negative titles found in the dataset.") |
I asked a question about why some code was incorrect. The answer is "because the input contains an extra curly brace }". Does this student answer say that? The issue lies in the fact that the `negative` list of titles is not present in the `titles` list. The code is searching for exact matches of the titles in the `negative` list within the `titles` list, but it is not finding any matches. Therefore, the length of `set1_no` remains 0. To fix this problem, make sure that the titles in the `negative` list are present in the `titles` list, or modify the code to properly handle cases where the titles are not found. Here is one possible change to the code:
1 2 3 | # Add a check to see if any titles were found in the negative list if not set1_no: print("No negative titles found in the dataset.") |
The student fails. The provided answer does not address the original issue mentioned, which was about an extra curly brace in the input. Instead, it discusses a mismatch between two lists (`negative` and `titles`) and provides a solution for handling cases where titles from the `negative` list are not found in the `titles` list. This does not relate to the problem of an extra curly brace in the input.
Testing if the previous output contains the string student passes
: False
Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
The problem is that the negative titles are not being matched correctly. The reason is that the `negative` argument received from the request contains additional characters that are not part of the actual title. Specifically, there is an extra curly brace `}` at the end of the negative title string. To fix this, you can modify the line where you split the negative argument to remove any unwanted characters before splitting. For example, you can use the following code:
1 2 | negative = request.args.get('negative', '').replace('}', '') negative = negative.split("##") |
I asked a question about why some code was incorrect. The answer is "because the input contains an extra curly brace }". Does this student answer say that? The problem is that the negative titles are not being matched correctly. The reason is that the `negative` argument received from the request contains additional characters that are not part of the actual title. Specifically, there is an extra curly brace `}` at the end of the negative title string. To fix this, you can modify the line where you split the negative argument to remove any unwanted characters before splitting. For example, you can use the following code:
1 2 | negative = request.args.get('negative', '').replace('}', '') negative = negative.split("##") |
The student passes.
Testing if the previous output contains the string student passes
: True
Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
The code is trying to find indices of the titles that are present in the positive and negative lists, but it seems that none of the titles are present in the negative list. This is why the length of `set1_no` is 0 and the output is `OK 1 0`. One possible reason for this is that the titles in the negative list are not present in the `titles` list. Another possible reason is that the titles in the negative list are not an exact match with the titles in the `titles` list. For example, there might be extra whitespace or punctuation that is causing the strings to be different. To fix this, you can try adding some error handling to see if the titles in the negative list are present in the `titles` list. You can also try printing out the `titles` list and the negative list to see if there are any differences in the formatting or content of the titles. Here is an example of how you might add some error handling to your code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [] for title in negative: if title in titles: keep_no.append(titles.index(title)) else: print(f"Title '{title}' not found in titles list") set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
I asked a question about why some code was incorrect. The answer is "because the input contains an extra curly brace }". Does this student answer say that? The code is trying to find indices of the titles that are present in the positive and negative lists, but it seems that none of the titles are present in the negative list. This is why the length of `set1_no` is 0 and the output is `OK 1 0`. One possible reason for this is that the titles in the negative list are not present in the `titles` list. Another possible reason is that the titles in the negative list are not an exact match with the titles in the `titles` list. For example, there might be extra whitespace or punctuation that is causing the strings to be different. To fix this, you can try adding some error handling to see if the titles in the negative list are present in the `titles` list. You can also try printing out the `titles` list and the negative list to see if there are any differences in the formatting or content of the titles. Here is an example of how you might add some error handling to your code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [] for title in negative: if title in titles: keep_no.append(titles.index(title)) else: print(f"Title '{title}' not found in titles list") set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
The student fails. The provided answer does not address the specific issue mentioned in the question about the input containing an extra curly brace "}". Instead, it discusses potential mismatches between the titles in the negative list and the titles list due to differences in formatting or content, and suggests adding error handling to identify titles in the negative list that are not present in the titles list. This does not directly answer the question about the incorrect code being due to an extra curly brace.
Testing if the previous output contains the string student passes
: False