# PyTorch negative-sampling question | Aced

Aced (formerly Exponent) publishes a public search API over its indexed pages; the guide is at https://www.aced.io/agents/agent-access.

Source: https://www.aced.io/questions/3189/modify-pytorch-code-negative-sampling
Source observed: 2026-11-05T00:41:46.068Z
Last checked: 2026-11-05T00:41:46.068+00:00
Indexed: 2026-11-07T02:57:40.006+00:00

---

# Modify this PyTorch pseudo-code to perform negative sampling if the `pos_ids` are known

We host this technical interview question in our community question library. It asks how to modify the following PyTorch-style pseudo-code for negative sampling when the positive IDs (`pos_ids`) are known:

```text
label #shape=[batch_s, pos_ids]
hidden #shape=[batch_s, ch]
logits #shape=[ch, C]
out=np.dot(logits, hidden(X)) #shape=[batch_s, C]
loss=cross_entropy(out, label)
```

## Question details

- **Role:** [Data Scientist](https://www.aced.io/questions?role=data-science)
- **Company:** [SAP](https://www.aced.io/questions?company=sap)
- **Category:** [Program Sense](https://www.aced.io/questions?type=program-sense)
- **Interview program:** Sense
- **Last asked:** 3 years ago

## Community answers

No community answers have been contributed yet. To answer, users must [log in or sign up](https://www.aced.io/signup?src=nav&returnPath=/questions/3189/modify-pytorch-code-negative-sampling). Submitting an answer marks the question complete.

Detailed company statistics for this question are available through [Upgrade](https://www.aced.io/upgrade?src=questions).

## Related courses

### [Data Science Interview Prep](https://www.aced.io/courses/data-science)

![Data Science Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/3U4C5C0OkDR0UeGch4AmlE/7ad489430b676a088cb973307fe77884/Data_Science_Interview_Prep_Course.jpeg?w=800&h=800&fm=webp&q=75)

Prepare for data science interviews at Google, Amazon, Microsoft, Meta, Apple, and other top companies with mock interviews, frameworks, and advice from senior candidates. Practice statistics, experimentation, coding, SQL, machine learning, and behavioral interviews.

### [SQL Interviews](https://www.aced.io/courses/sql-interviews)

![SQL Interviews](https://images.ctfassets.net/x78yjrjc11pq/62mN54S54HpLIOmyG8qbnq/54deaf5e397d0807d71c0e27e21e5ee3/sql_illustration_2.jpg?w=800&h=800&fm=webp&q=75)

Prepare for SQL interviews by practicing syntax basics, aggregations, and window functions. Learn to manipulate data, write complex queries, and analyze information from diverse datasets.

## Explore Aced

We provide interview preparation courses and practice resources across product management, forward-deployed engineering, engineering management, software engineering, system design, data science, machine learning, data engineering, AI engineering, investment banking, generative AI, security engineering, TPM, solutions architecture, UX/product design, and BizOps & Strategy.

Our question library includes product management, behavioral, coding, system design, SQL, machine learning, investment banking, and data engineering questions. We also offer practice, mock interviews and coaching, resume review, salary negotiation, job referrals, resources, and experiences.

---

[Read this page’s summary](https://www.aced.io/agents/api/public/v1/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3189%2Fmodify-pytorch-code-negative-sampling&trace=t_679ff9ab98f3)

## Ask a follow-up about this page

Need a more specific answer? Ask the exact question you have. It returns a fresh, cited answer from Aced (formerly Exponent)’s knowledge base. No account or API key required.

Open this URL with your own question, URL-encoded. Include your question in q. All research inputs are optional; no account or setup.

`GET https://www.aced.io/agents/agent/faq?q={question}&trace=t_679ff9ab98f3`

[Tool guide and examples](https://www.aced.io/agents/agent-access) · [OpenAPI](https://www.aced.io/agents/api/public/v1/openapi.json) · [Page TLDR form](https://www.aced.io/agents/agent-tools/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3189%2Fmodify-pytorch-code-negative-sampling). Opening a form does not execute a tool.