Bug in book chapter 12

Running the code in chapter 12 gives me errors:
Code:

learn = Learner(dls, LMModel7(len(vocab), 64, 2, 0.5),
                loss_func=CrossEntropyLossFlat(), metrics=accuracy,
                cbs=[ModelResetter, RNNRegularizer(alpha=2, beta=1)])
learn.fit_one_cycle(15, 1e-2, wd=0.1)

Error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[48], line 1
----> 1 learn.fit_one_cycle(15, 1e-2, wd=0.1)

File D:\Program Files\Python310\lib\site-packages\fastai\callback\schedule.py:121, in fit_one_cycle(self, n_epoch, lr_max, div, div_final, pct_start, wd, moms, cbs, reset_opt, start_epoch)
    118 lr_max = np.array([h['lr'] for h in self.opt.hypers])
    119 scheds = {'lr': combined_cos(pct_start, lr_max/div, lr_max, lr_max/div_final),
    120           'mom': combined_cos(pct_start, *(self.moms if moms is None else moms))}
--> 121 self.fit(n_epoch, cbs=ParamScheduler(scheds)+L(cbs), reset_opt=reset_opt, wd=wd, start_epoch=start_epoch)

File D:\Program Files\Python310\lib\site-packages\fastai\learner.py:272, in Learner.fit(self, n_epoch, lr, wd, cbs, reset_opt, start_epoch)
    270 self.opt.set_hypers(lr=self.lr if lr is None else lr)
    271 self.n_epoch = n_epoch
--> 272 self._with_events(self._do_fit, 'fit', CancelFitException, self._end_cleanup)

File D:\Program Files\Python310\lib\site-packages\fastai\learner.py:207, in Learner._with_events(self, f, event_type, ex, final)
    206 def _with_events(self, f, event_type, ex, final=noop):
--> 207     try: self(f'before_{event_type}');  f()
    208     except ex: self(f'after_cancel_{event_type}')
    209     self(f'after_{event_type}');  final()

File D:\Program Files\Python310\lib\site-packages\fastai\learner.py:261, in Learner._do_fit(self)
    259 for epoch in range(self.n_epoch):
    260     self.epoch=epoch
--> 261     self._with_events(self._do_epoch, 'epoch', CancelEpochException)

File D:\Program Files\Python310\lib\site-packages\fastai\learner.py:207, in Learner._with_events(self, f, event_type, ex, final)
    206 def _with_events(self, f, event_type, ex, final=noop):
--> 207     try: self(f'before_{event_type}');  f()
    208     except ex: self(f'after_cancel_{event_type}')
    209     self(f'after_{event_type}');  final()

File D:\Program Files\Python310\lib\site-packages\fastai\learner.py:255, in Learner._do_epoch(self)
    254 def _do_epoch(self):
--> 255     self._do_epoch_train()
    256     self._do_epoch_validate()

File D:\Program Files\Python310\lib\site-packages\fastai\learner.py:247, in Learner._do_epoch_train(self)
    245 def _do_epoch_train(self):
    246     self.dl = self.dls.train
--> 247     self._with_events(self.all_batches, 'train', CancelTrainException)

File D:\Program Files\Python310\lib\site-packages\fastai\learner.py:207, in Learner._with_events(self, f, event_type, ex, final)
    206 def _with_events(self, f, event_type, ex, final=noop):
--> 207     try: self(f'before_{event_type}');  f()
    208     except ex: self(f'after_cancel_{event_type}')
    209     self(f'after_{event_type}');  final()

File D:\Program Files\Python310\lib\site-packages\fastai\learner.py:213, in Learner.all_batches(self)
    211 def all_batches(self):
    212     self.n_iter = len(self.dl)
--> 213     for o in enumerate(self.dl): self.one_batch(*o)

File D:\Program Files\Python310\lib\site-packages\fastai\learner.py:243, in Learner.one_batch(self, i, b)
    241 b = self._set_device(b)
    242 self._split(b)
--> 243 self._with_events(self._do_one_batch, 'batch', CancelBatchException)

File D:\Program Files\Python310\lib\site-packages\fastai\learner.py:207, in Learner._with_events(self, f, event_type, ex, final)
    206 def _with_events(self, f, event_type, ex, final=noop):
--> 207     try: self(f'before_{event_type}');  f()
    208     except ex: self(f'after_cancel_{event_type}')
    209     self(f'after_{event_type}');  final()

File D:\Program Files\Python310\lib\site-packages\fastai\learner.py:227, in Learner._do_one_batch(self)
    225 self('after_pred')
    226 if len(self.yb):
--> 227     self.loss_grad = self.loss_func(self.pred, *self.yb)
    228     self.loss = self.loss_grad.clone()
    229 self('after_loss')

File D:\Program Files\Python310\lib\site-packages\fastai\losses.py:56, in BaseLoss.__call__(self, inp, targ, **kwargs)
     54 if self.floatify and targ.dtype!=torch.float16: targ = targ.float()
     55 if targ.dtype in [torch.int8, torch.int16, torch.int32]: targ = targ.long()
---> 56 if self.flatten: inp = inp.view(-1,inp.shape[-1]) if self.is_2d else inp.view(-1)
     57 return self.func.__call__(inp, targ.view(-1) if self.flatten else targ, **kwargs)

AttributeError: 'tuple' object has no attribute 'view'

This code is strictly from the book, at the end of chapter 12. The book says the code does the same thing as

learn = TextLearner(dls, LMModel7(len(vocab), 64, 2, 0.4), loss_func=CrossEntropyLossFlat(), metrics=accuracy)

But the latter piece doesn’t give errors.
Is there something wrong with the book’s code?