Unit 9 · Exercises
Unit 9 exercises
These exercises use the definitions of Lessons 9.1 to 9.3. The calculations can be checked with a few lines of Python.
Exercise 1. A voice deepfake detector at a call center
A bank's call center receives 50,000 calls a day. A voice deepfake detector flags 3% of genuine calls and 85% of calls that use synthetic speech. Suppose 1 in 20,000 calls uses synthetic speech. (a) How many alerts per day does the detector raise, and how many of them are real? (b) What is its precision? (c) Suggest a way to use the detector that makes its output useful despite (b).
Show the answer
(a) There are \(50{,}000/20{,}000 = 2.5\) synthetic calls a day, of which \(0.85 \times 2.5 \approx 2.1\) are flagged. The \(49{,}997.5\) genuine calls produce \(0.03 \times 49{,}997.5 \approx 1{,}500\) false alerts, so the detector raises about 1,502 alerts a day, about 2 of them real.
(b) Precision is \(2.125/1{,}502 \approx 0.0014\), about one real alert in 700.
(c) Screening every call is hopeless at this base rate. The detector becomes useful where the base rate is much higher, for example only on calls that request a high-risk action such as changing a payee, raising a limit or resetting authentication. There, a flag can trigger the out-of-band verification that the procedure of Lesson 9.3 requires anyway, so a false alert costs one call-back instead of an investigation, and the verification protects against the synthetic calls the detector misses.
Exercise 2. Where the checkerboard comes from
A one-dimensional transposed convolution with stride 2 and kernel \([k_0, k_1, k_2] = [1, 1, 1]\) is applied to an input of six ones, so that input element \(i\) adds \(k_j\) to output position \(2i + j\). (a) Write out the 13 output values. (b) Explain why the output has a component at the highest representable frequency, 0.5 cycles per sample. (c) What changes if the kernel has length 4?
Show the answer
(a) Positions \(2i\), \(2i+1\) and \(2i+2\) receive a contribution from input \(i\). Even interior positions are reached from two inputs (as the end of one window and the start of the next) and odd positions from one, so the output is 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1.
(b) Apart from the ends, the output alternates between 2 and 1, so it is a constant 1.5 plus an alternating term of amplitude 0.5. An alternation with period 2 samples is exactly the frequency 0.5 cycles per sample, the Nyquist frequency. The input was constant, so this energy is created by the uneven overlap, which is what Odena et al. (2016) describe and what produces checkerboards in two dimensions, where the overlap counts of the two axes multiply.
(c) With the kernel \([1, 1, 1, 1]\) and stride 2, every interior output position is reached by exactly two windows, the overlap is even, and a constant input gives a constant interior output of 2. For a general kernel \([k_0, k_1, k_2, k_3]\), even interior positions receive \(k_0 + k_2\) and odd ones \(k_1 + k_3\), so the alternation disappears only if these two sums are equal. Odena et al. (2016) observe that networks with even overlap often learn kernels that cause similar artifacts. Lab 9's second "Try this" item uses a random 4-by-4 kernel, whose four interleaved sub-kernels have different sums, so expect the periodic pattern to remain.
Exercise 3. A three-step diffusion process
A toy diffusion model has three steps with \(\beta_1 = 0.1\), \(\beta_2 = 0.2\), \(\beta_3 = 0.3\). (a) Compute \(\bar\alpha_t\) for \(t = 1, 2, 3\). (b) Write \(x_3\) as a function of \(x_0\) and a standard Gaussian \(\epsilon\). (c) A pixel has value \(x_0 = 0.8\) and the sampled noise is \(\epsilon = -1\). What is \(x_3\)?
Show the answer
(a) \(\alpha_t = 1 - \beta_t\) gives 0.9, 0.8 and 0.7, so \(\bar\alpha_1 = 0.9\), \(\bar\alpha_2 = 0.72\) and \(\bar\alpha_3 = 0.504\).
(b) From \(q(x_t \mid x_0)\), a Gaussian with mean \(\sqrt{\bar\alpha_t}\, x_0\) and covariance \((1 - \bar\alpha_t) I\),
(c) Substituting \(x_0 = 0.8\) and \(\epsilon = -1\),
After three steps the signal and the noise have nearly equal weight. Real models use many more steps with smaller \(\beta_t\), so that each reverse step only has to remove a little noise.
Exercise 4. When is a text watermark detectable?
A text watermark uses a green-list fraction \(\gamma = 0.25\) and flags a text of \(T\) tokens, of which \(|s|_G\) are green, when the statistic
exceeds 4. (a) A 120-token message contains 48 green tokens. Is it flagged? (b) A 240-token message has the same green fraction, 96 green tokens. Is it flagged? (c) An attacker rewrites 10 tokens of the 240-token message, which in the worst case for the defender turns 20 green tokens red. Is it still flagged?
Show the answer
(a) \(\gamma T = 30\), and the denominator is \(\sqrt{22.5} \approx 4.74\), since \(120 \times 0.25 \times 0.75 = 22.5\). So \(z = 18/\sqrt{22.5} \approx 3.79\), below 4. The message is not flagged, although 40% of its tokens are green against 25% expected.
(b) \(\gamma T = 60\), and the denominator is \(\sqrt{45} \approx 6.71\), since \(240 \times 0.1875 = 45\). So \(z = 36/\sqrt{45} \approx 5.37\), and the message is flagged. The same green fraction gives stronger evidence in a longer text, because \(z\) grows with \(\sqrt{T}\) at a fixed fraction.
(c) With 76 green tokens, \(z = 16/\sqrt{45} \approx 2.39\), and the message is no longer flagged. Rewriting about 4% of the tokens was enough here because the original watermark was weak; a strongly watermarked long text needs far more edits, as Kirchenbauer et al. (2023) show. Watermark evidence is a statistic, and its strength depends on length, watermark strength and editing.
Exercise 5. The value of the GAN game at its optimum
For a fixed generator with density \(p_g\), the optimal discriminator is
(a) Show that when \(p_g = p_{\mathrm{data}}\), the value \(V(D^*, G)\) of the minimax game in Lesson 9.1 is \(-\log 4\). (b) What does a discriminator output of 1/2 everywhere imply for a detector of the generator's images trained in the same way?
Show the answer
(a) With \(p_g = p_{\mathrm{data}}\), \(D^*(x) = 1/2\) for every \(x\). Then
which is the global minimum identified by Goodfellow et al. (2014).
(b) At that optimum, no function of the image can tell generated samples from training data better than chance, because the two distributions are identical. Real generators do not reach it, which is why detectors work at all, but the better a generator matches the data distribution, the less there is for any detector to find. Detection based on generator artifacts is a race against generator quality, and controls that do not depend on the content (Lesson 9.3) do not have this weakness.
Exercise 6. Training with compression in Lab 9
In Lab 9, the spectral detector trained on nearest-neighbor fakes kept a high AUC after JPEG compression but flagged almost none of the compressed fakes at its original threshold. (a) Explain why the AUC and the share of flagged fakes can disagree. (b) Modify the lab to compress half of the training images (real and fake, chosen at random) with JPEG at quality 75 before computing their spectra, retrain the detector, and test it on uncompressed and compressed test images. What do you expect, and what should you measure besides AUC?
Show the answer
(a) AUC depends only on the ranking of test scores. The detector relies mostly on the last ring of the spectrum, where nearest-neighbor fakes have a much lower mean log magnitude than real images because their spectrum is exactly zero at the frequencies with a horizontal or vertical component of 0.5 cycles per pixel. JPEG compression puts nonzero values at those frequencies and raises the mean log magnitude of the fakes' last ring close to that of real images. Their scores fall sharply, below the default threshold of 0.5 that the detector also applies to uncompressed data (few fakes flagged), while the scores of real images change little and stay lower still, so most fakes are still ranked above most real images (high AUC). A deployed detector operates at a threshold, so the shift matters.
(b) Replace the training set by one in which a random half of the real and fake images has been passed through jpeg(), recompute spectra(), and refit the pipeline. The detector then sees both conditions during training, so its threshold should transfer to compressed test images, possibly at some cost on uncompressed ones. Wang et al. (2020) found that blur and JPEG augmentation improved detection on most of their test generators but lowered it on two. Report the share of fakes flagged and the share of real images flagged at the threshold, on both uncompressed and compressed test images, not only the AUC.
Exercise 7. Designing a payroll-change procedure
The payroll team of a company receives requests from employees to change the bank account into which their salary is paid. Requests arrive by email, by phone and occasionally by video call. Describe a procedure that resists impersonation with cloned voices and real-time video, using the controls of Lesson 9.3, and explain what an attacker would need to defeat it.
Show the answer
A change of bank account redirects salary payments, so every such request is treated as unusual regardless of channel. The payroll officer does not act on the channel that delivered the request. They call the employee back on the number recorded in the HR system (not one supplied in the request) and also send a confirmation through an authenticated channel, such as a notification in the HR portal that requires the employee's login with multifactor authentication. The change takes effect only after a waiting period, and a notice of the change is sent to the employee's contact details recorded before the request. Requests that ask for secrecy or speed, or that arrive while the employee is said to be unreachable, are escalated to a second officer. Video or voice confirmation on a call that the requester initiated never counts.
To defeat this, an attacker needs more than a convincing voice or face. They must answer a call-back to the employee's recorded number, which requires taking over that phone line, and pass the portal's multifactor authentication, which requires compromising the account and its second factor, before that notice reaches the real employee. Each of these is a separate compromise that a deepfake does not provide.
References
- Goodfellow, I. J., Pouget-Abadie, J., Mirza, M., Xu, B., Warde-Farley, D., Ozair, S., Courville, A., and Bengio, Y. (2014). Generative adversarial nets. Advances in Neural Information Processing Systems, 27. https://proceedings.neurips.cc/paper_files/paper/2014/hash/f033ed80deb0234979a61f95710dbe25-Abstract.html
- Kirchenbauer, J., Geiping, J., Wen, Y., Katz, J., Miers, I., and Goldstein, T. (2023). A watermark for large language models. Proceedings of the 40th International Conference on Machine Learning (ICML), PMLR, 202, 17061-17084. https://proceedings.mlr.press/v202/kirchenbauer23a.html
- Odena, A., Dumoulin, V., and Olah, C. (2016). Deconvolution and checkerboard artifacts. Distill, 1(10). https://doi.org/10.23915/distill.00003
- Wang, S.-Y., Wang, O., Zhang, R., Owens, A., and Efros, A. A. (2020). CNN-generated images are surprisingly easy to spot ... for now. 2020 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 8692-8701. https://doi.org/10.1109/CVPR42600.2020.00872